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 the myscript.sh script in the background, and redirects the output and error output to the nohup.out file in the current directory.
  • nohup ./myscript.sh > output.log 2>&1 &: This runs the myscript.sh script in the background, and redirects the output and error output to the output.log file in the current directory.
  • nohup -p pidfile ./myscript.sh &: This runs the myscript.sh script in the background, and writes the process ID of the command to the pidfile.
  • nohup -o output.log -e error.log ./myscript.sh &: This runs the myscript.sh script in the background, and redirects the output to the output.log file and error output to the error.log file.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

  1. […] Once installed, let’s first allow TCP traffic over your SSH port so that you don’t get locked out of…

  2. […] have the option to choose between Password and SSH key selection. Learn more about SSH keys here. It’s recommended…