Cron

From Hackepedia
Revision as of 20:04, 7 July 2006 by Franks (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
man 5 crontab

This will show you the layout of the crontab file for your system. Modern cron for example take schedules like @daily and @monthly now as well as the traditional 5 space delimited digit fields for date and time. Typically:

            field          allowed values
             -----          --------------
             minute         0-59
             hour           0-23
             day of month   1-31
             month          1-12 (or names, see below)
             day of week    0-7 (0 or 7 is Sun, or use names)

and you follow that with the command you want to run. Remember, the output will be mailed to the user@ so redirect the output to /dev/null if you don't want this, however this is a risk if something goes awry. Let's see if we have anything in our cron yet:

$ crontab -l
$


It is still empty, so we'll create one. Do note that it will open cron in your EDITOR field.

$ env | grep EDITOR


Let's say we want to download a file every 6 hours, and have the stdout go to /dev/null

$ crontab -e

and add this line:

 * 0,6,12,18 * * * /usr/bin/wget -O ~/slashdot.xml  http://slashdot.org/slashdot.xml 1>/dev/null 

This requires /usr/bin/wget of course.