You may wish to run scripts or other administration tools in an automated fashion on a regular basis. The Unix cron program will allow you to do this. If you run crontab -e from the command line, it will bring up an editor. [5] In this editor, you can add or edit the names of programs to be run. The account from which you run the crontab program is the account that will execute the programs later on. If the program should be run as root, make sure to run crontab as root when you add the entry.
Each line of the file specifies one program to run. The first five fields denote the time the program should be started. They are, in order:
An asterisk can be used in any of these fields to indicate that every value is acceptable. For example, 00 1 * * * would mean that the program should be run every day at 1:00 a.m. Following the timing information is the name of the program to run and its arguments. For example: Solaris# crontab -l 37 * * * * /usr/lib/sendmail -q > /dev/null 2> /dev/null As you can see, running the crontab program with the -l option will print the current configuration. Here the mail queue is run every hour at 37 minutes past the hour. The standard output and standard error are redirected to /dev/null because, otherwise , cron will send output in email, and in this case, it was decided that it would be preferable not to receive any error messages. Here's another example: Solaris# crontab -l 05 9 * * * /usr/local/bin/report.pl -e > /dev/null This runs a report program every day at 9:05 a.m. The program sends email to administrators about problem conditions that have arisen within the past day. After you edit the crontab file, save and exit the editor, and the changes will be complete. You should test the script to make sure it works correctly from cron . |