What Cron Can Do For You
Cron allows users to automate repetitive system administration tasks such as tape backups, database reorganization, and general file cleanups (such as emptying log files and queues).
The Crontab File's Syntax
To tell cron what you want it to run, and how often you want it to run it, you need to create a crontab file. A crontab file is just a text file with the following syntax:
minute hour day-of-month month-of-year day-of-week command
Each of the above columns can be in one of the following formats (these examples are for the minute column):
30
Run command at 30 minutes past the hour.
0-59/10
Run command once every 10 minutes, for the entire hour.
15-30
Run command once every minute, from 15 to 30 minutes past the hour.
0,10,50
Run command at 0 minutes past the hour, 10 minutes past the hour, and 50 minutes past the hour.
*
Run command once every minute.
And here's the range of numbers available for each of the time and date columns:
minute : 0-59
hour : 0-23
day-of-month : 0-31
month-of-year: 1-12
day-of-week : 0-6
(0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat)
Here's an example crontab file:
30 0 * * * ./backup.sh
0,10,50 9-15 * * * ./compute.sh
0-59/10 * * * 1,3,5 ./netgrab.sh
30 0 * * * ./backup.sh
Run the backup.sh script (located in your home directory) at half-past (30) midnight (0), on every day of the month (*), and every day of the year (*), and every day of the week (*).
0,10,50 9-15 * * * ./compute.sh
Run the compute.sh script every 0 minutes, 10 minutes, and 50 minutes past the hours (0,10,50), between 9am and 5pm (9-15), every day of the year.
0-59/10 * * * 1,3,5 ./netgrab.sh
Run the netgrab.sh script every 10 minutes (0-59/10), every Monday, Wednesday, and Friday (1,3,5).
Copied from Newbies Linux Manual, Automatings things with cron.
|