If you are running a process and you don’t think it will be completed by the time you log out for the day, use the nohup command. Nohup will continue processing when you exit your account. Nohup means no hang up.
The general format of the command is:
nohup command &
Any output from your job will be redirected to a file called ‘ nohup.out ’, unless you specify otherwise with
nohup command >myout.file 2>&1
which sends all output to the file myout.file.
Let’s do an example and test that it actually does continue working after you have logged out. We’ll kick off a log cleanup script called ps1.
$ nohup ps1 &
[1] 179
$ nohup: appending output to `nohup.out`
Now exit the shell, log back in again, and run the following command:
$ ps x |grep ps1
179 ? S N 0:01 sh /root/ps1
506 p2 S 0:00 grep ps1
The script is still working. Use ps -ef |grep ps1 if your system does not support ps x.
If you want to run several commands at once, it’s best to stick them together in a script file then execute it using nohup. For example the following commands have all been piped together; stick all these commands into a file, and make it executable.
cat /home/accounts/qtr_0499 | /apps/bin/trials.awk |sort|lp
$ cat > quarterend
cat /home/accounts/qtr_0499 | /apps/bin/trials.awk |sort|lp
<CTRL-D>
Now make it executable:
$ chmod 744 quarterend
We’ll also stick all the output into a file called qtr.out:
$ nohup ./quarterend > qtr.out 2>&1 &
[5] 182
18.118.31.156