3.4. The nohup command

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 & 

3.4.1. Submitting a job using nohup

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.

3.4.2. Submitting several jobs at once

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
						

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.156