Certification Objective 11.03: anacron and tmpwatch

 < Day Day Up > 

There are two cron jobs which are critical for basic system administration. The anacron RPM package makes sure that cron jobs are run on computers that may be powered down during the night. The tmpwatch RPM configures cron jobs which removes files from various /tmp directories that have not been accessed in a specified number of hours.

Exam Watch 

As of this writing, anacron is listed as part of the RHCT prep course (RH133). It is therefore an implicit part of the requirements for both Red Hat exams. However, the anacron RPM package is not included as part of RHEL 3. There's an open request to add it to RHEL 3; see bug 103691 at bugzilla.redhat.com for more information. You'll have to make your own judgment on whether to study anacron for your exam. Watch for changes in the Red Hat Exam Prep guide and RH133 syllabus. In my opinion, anacron is still an excellent tool for Linux administrators.


Some of the cron jobs described in Chapter 5 are essential to the smooth operation of a RHEL 3 computer. And if you add backup jobs to the cron directories, you want to make sure the backups are always executed. For example, if there is a power failure when you schedule a backup job, you may never know that the backup wasn't created-at least until you need the backup that you don't have.

Since the anacron RPM is not included with RHEL 3, you'll need to get the RPM from a different source, such as the Red Hat Linux 9 or Fedora Linux installation files. If it is included on your Red Hat exam, you should be able to install it from some readily available source, as you won't have access to the Internet during your exam. Therefore, all I'll say for the purposes of this book is that you can download the anacron RPM from a source such as ftp.redhat.com or a mirror site such as those specified at www.redhat.com/download/mirror.html.

Once installed, the anacron command checks the jobs of your choice, based on the settings in the /etc/anacrontab configuration file. The default version of this file is straightforward. The first two lines set the SHELL and PATH for commands in the remainder of the file:

SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

The following three commands run the cron scripts in the noted directories:

1   65   cron.daily    run-parts /etc/cron.daily 7   70   cron.weekly   run-parts /etc/cron.weekly 30  75   cron.monthly  run-parts /etc/cron.monthly

These commands are in the following format:

period delay job-identifier command 

In this format, anacron checks the jobs in the job-identifier directory every period (in days). If one or more jobs in this directory have not been run, the command is executed after the given delay (in minutes).

In other words, if you've installed the anacron RPM, RHEL 3 runs the anacron service every time Linux boots on your computer. Take the last command in this list. The anacron service checks the commands in the /etc/cron.monthly directory. If they have not been run for 30 days, anacron waits 75 minutes, and then executes the run-parts /etc/cron.monthly command, which executes the scripts in the /etc/cron.monthly directory.


As its name implies, the tmpwatch script is normally run on directories such as /tmp and /var/tmp. The tmpwatch script works recursively, so if you specify the top-level directory in a tree, tmpwatch will search through the entire directory tree looking for files to remove.

The following tmpwatch command deletes all files in the /tmp directory that haven't been accessed in the past week (168 hours = 7 days × 24 hours/day):

# tmpwatch 168 /tmp

While you can run the tmpwatch command from the command line, it is often more practical to set it up to be run by the cron daemon on a regular basis. It's run as a script on a daily basis, in the /etc/cron.daily directory. By default, RHEL 3 configures the first two commands in tmpwatch to delete files in /tmp and /var/tmp every 10 and 30 days, respectively:

/usr/sbin/tmpwatch 240 /tmp /usr/sbin/tmpwatch 720 /var/tmp

The final command deletes formatted manuals, which are cached and stored in various /var/cache directories, every 30 days.

for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do     if [ -d "$d" ]; then         /usr/sbin/tmpwatch -f 720 $d     fi done 

Exercise 11-3: Clearing an Imaginary /db Directory

start example

In a bizarre twist of fate, a runaway process has just created 200 temporary files in /db that it did not remove. You could remove them manually, or you can let tmpwatch delete all the files that are more than one hour old. Note that this removes all files over an hour old, not just these imaginary files, so this should not be done on a production server directory. If you already have a directory named /db, do not use it. If necessary, create a separate directory just for the purpose of this exercise.

# cp /etc/* /db   # copying a large number of files to /db # ls /db | wc -w  # how may files need to be removed

Wait at least an hour.

# tmpwatch 1 /db # ls /db          # files should be gone

Alternatively, you can copy or extract files from an older backup or tar archive to the /db directory, and have tmpwatch delete them. If they are all more than seven days old, then use 168 as the waiting period. You could even try various times to see which files are deleted.

end example

 < Day Day Up > 

RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
ISBN: 71765654
Year: 2003
Pages: 194

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net