nohup, short for “no hangup”, is a utility used to run a command or script that continues to run even after the user logs out or terminates the session.
Basic Syntax
nohup command [options] [arguments] &
Here, command specifies the command or script to be executed, options specifies any command-line options that the command may require, and arguments specifies any arguments that the command may require. The & symbol at the end of the command runs the command in the background.
Commonly Used Options
-
-p: This specifies the PID (process ID) file where the process ID of the command is written. -
-o file: This specifies the file where the output of the command is redirected. -
-e file: This specifies the file where the error output of the command is redirected.
Useful Examples
-
nohup ./myscript.sh &: This runs themyscript.shscript in the background, and redirects the output and error output to thenohup.outfile in the current directory. -
nohup ./myscript.sh > output.log 2>&1 &: This runs themyscript.shscript in the background, and redirects the output and error output to theoutput.logfile in the current directory. -
nohup -p pidfile ./myscript.sh &: This runs themyscript.shscript in the background, and writes the process ID of the command to thepidfile. -
nohup -o output.log -e error.log ./myscript.sh &: This runs themyscript.shscript in the background, and redirects the output to theoutput.logfile and error output to theerror.logfile.
Leave a Reply