Section 14.10. Automating Tasks


[Page 589 (continued)]

14.10. Automating Tasks

There are several system tasks that are fairly simple but tedious to perform. For example:

  • checking disk space usage

  • performing incremental backups

  • cleaning up temporary directories (/tmp) and old "core" files

One of the powers of Linux is its capacity to run simple shell scripts or C programs you've written to automate tasks that you currently perform by hand. I recommend that you automate as many of these chores as you can. Tasks that must be executed on a periodic basis can be scheduled by the cron utility. The cron utility allows you to schedule a program to run anywhere from once every minute to once every year. This is accomplished by using the crontab command (discussed on page 135 of Chapter 4, "GNU Utilities for Power Users"). Any messages generated by the program are sent via e-mail to the user who registered the program to be run.

For example, a simple script to see if any of your file systems are at 90% capacity or greater might be:

#!/bin/sh # df | egrep "9[0-9]%|100%" 



[Page 590]

If this script is registered by "root" with cron to be run every hour, nothing (visible) happens until a file system reaches 90% capacity or greater. The script is run every hour but no output is generated. When a file system reaches 90%, the search pattern specified to the egrep command will be satisfied by the line in the df output corresponding to the offending file system, so the script will generate a line of output. This line will be e-mailed to "root," so within one hour of the file system's hitting 90%, you'll know about it.

You can write all kinds of simple shell scripts to monitor nearly anything about your system and only send e-mail when some threshold is reached that triggers concern.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

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