UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 1: Topics in Administration |
|
||||||||||||||||||||||||||||||||||||
|
To keep processes running after you log out, use the nohup command. This command will be immune to any hang-ups and quits.
Flavors: AT&T, BSD
Shells: All
Syntax:
nohup command arguments
To use this command, have nohup precede the command that you don't want to die when you exit the shell of system. While this process is running, the shell, desktop, or windowing system can be exited without any harm to the command that is passed through nohup. The only thing that would end this process is a kill signal, an error in the process, or a reboot of the system.
On some flavors of UNIX running in certain shells, nohup creates a file that sends any output passed to standard out from the process that was executed within nohup. The file is called nohup.out and is located in the current directory (where the command was initiated).
Later versions of UNIX have adapted the nohup command when you send a process into the background. Irix and Solaris are two flavors that have incorporated this method. Even though nohup is no longer needed, these flavors have grandfathered the command for those who still use it in their scripts and routines.
$ nohup tar -cvf /dev/tape /home &
This example runs in background and transfers all the files located in /home, in .tar format, to the local tape (your tape device might differ). The file nohup.out potentially creates a list of the files that are being transferred to the tape.
Using nohup with other commands to which processes can be passed helps to ease administrative tasks. These next two examples show you how nice and rsh can be passed to create one long command.
Flavors: AT&T, BSD
$ nohup nice /usr/local/bin/build_report.sh
If you're afraid that a process might take up too much CPU time, nohup can be joined with other commands (such as nice) to ease the load on the system. In this example, build_report might be a CPU intensive script that overloads the system (building various reports) if not run in a nice state.
Flavors: AT&T, BSD
$ nohup rsh rocket '(find / -print)' > /tmp/foo.txt &
Listing the files of a large server can take a while. In this example, while you are logged off the system the command opens a shell on a remote system, finds all the files on that system, and outputs a list in a file on the local system (where nohup was initiated).
In the early years of UNIX, there was no graphical interface and no way to perform a screen lock. A user or operator did not have to remain logged in to a system until it was shut down. For security reasons and so that an operator didn't have to waste time hanging around for a job to finish, nohup was the perfect tool. It also allowed many administrators to go home after a long shift at work!
Each example shows how I have used this command in the past. It is a useful and powerful tool when you have multiple isolated systems to support and you cannot stay logged in to more than one at a time. This command also helps to let an overworked administrator go home while jobs are running that have been manually started.
Man pages:
find, nohup, nice, rsh
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 1: Topics in Administration |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.