Pages

Wednesday, October 3, 2012

nohup Execute Commands After You Exit From a Shell Prompt


Most of the time you login into remote server via ssh. If you start a shell script or command and you exit (abort remote connection), the process / command will get killed. Sometime job or command takes a long time. If you are not sure when the job will finish, then it is better to leave job running in background. However, if you logout the system, the job will be stopped. What do you do?

nohup command

Answer is simple, use nohup utility which allows to run command./process or shell script that can continue running in the background after you log out from a shell:

nohup Syntax:

nohup command-name &
Where,
  • command-name : is name of shell script or command name. You can pass argument to command or a shell script.
  • & : nohup does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an & symbol.

nohup command examples

1) Login to remote server
$ ssh user@remote.server.com
2) Execute script called pullftp.sh
# nohup pullftp.sh &

No comments:

Post a Comment