UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

1.8 Keep It Up with nohup

1.8.1 Description

1.8.1 Description

To keep processes running after you log out, use the nohup command. This command will be immune to any hang-ups and quits.

Example One: Basic nohup Command Use

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.

Example Two: Low priority nohup

Flavors: AT&T, BSD

Shells: All

$ 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.

Example Three: Multiple Command, Multiple System nohup

Flavors: AT&T, BSD

Shells: All

$ 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).

Reason

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!

Real World Experience

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.

Other Resources

Man pages:

find, nohup, nice, rsh

UNIX Hints & Hacks

ContentsIndex

Chapter 1: Topics in Administration

 

Previous ChapterNext Chapter

Sections in this Chapter:

1.1 Collecting System Information

 

1.7 Swap on-the-Fly

 

1.13 Remove the ---- Dashes ----

1.2 Backup Key Files!

 

1.8 Keep It Up with nohup

 

1.14 echo Does ls

1.3 Execution on the Last Day of a Month

 

1.9 Redirecting Output to Null

 

1.15 Building Large Dummy Files

1.4 Dealing with Unwanted Daemons

 

1.10 Keeping Remote Users Out

 

1.16 Burning-in Disk Drives

1.5 Keep Those Daemons Running

 

1.11 Rewinding Tapes Fast

 

1.17 Bringing a System Down

1.6 fuser Instead of ps

1.12 Generating a Range of Numbers

 

 

© Copyright Macmillan USA. All rights reserved.