Run the script using nohup without hitting enter key two times

Run the script using nohup without hitting enter key two times

As we have seen when we run the command with ‘nohup’ and ‘&’ so that the command should run at background even the terminal get disconnected we have to press enter key 2 times. To overcome from this problem,use the below given method.
Note: You can write the same in script as well

nohup command_name-Or-Script-name > Output.out 2> Error.err < /dev/null &

For eg. I have a command called ABC and I want to run directly from terminal you can write like this

nohup ABC > Output.out 2> Error.err < /dev/null &

OR if you want to run this command from script,you can use it like this.
create a script file,here I am creating shell script

vi test.sh

#!/bin/bash
nohup command_name-Or-Script-name > Output.out 2> Error.err < /dev/null & Save and exit by pressing ESC key then typing :wq

Or if you have any script called SCRIPTABC which actually do not run at background. It should be run like this directlt from terminal.

nohup SCRIPTABC > Output.out 2> Error.err < /dev/null &

Note: It will crate two file Output.out and Error.err . It is good tip to use in this way. Because from this file you can also get to know what was the output or if there was any error.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.