Filed in archive
by Michael Hammer on September 8, 2006
When scheduling a cron job each column indicates a different time period:
minute hour [Day of Month] [Month] [Day of Week]
Thus, to schedule a job to run at 5 minutes after every hour:
5 * * * * /job
every five minutes:
0-59/5 * * * * /job
some versions of cron allow the abbreviation: */5 * * * * /job
every hour on the hour:
0 * * * * /job
On the first of every month (at 1 am):
0 1 1 * * /job
---
Field Meaning
1 Minute (0-59)
2 Hour (2-24)
3 Day of month (1-31)
4 Month (1-12, Jan, Feb, ...)
5 Day of week (0-6) 0 = Sunday, 1 = Monday, ... or Sun, Mon, etc)
6 Command to execute
Some versions of cron allow an extra field before the command to
specify the user that the command will run as.
---
35 2 * * * root tar czf /usr/local/backups/daily/abc.tar.gz /abc >/dev/null 2>&1
This will run tar czvf /usr/local/backups/daily/abc.tar.gz /abc at 2:35am every day.
The > /dev/null 2>&1 part means to send any standard output to /dev/null and
to redirect standard error (2) to the same place as the standard output (1).
Basically it runs the command without any output to a terminal.
minute hour [Day of Month] [Month] [Day of Week]
Thus, to schedule a job to run at 5 minutes after every hour:
5 * * * * /job
every five minutes:
0-59/5 * * * * /job
some versions of cron allow the abbreviation: */5 * * * * /job
every hour on the hour:
0 * * * * /job
On the first of every month (at 1 am):
0 1 1 * * /job
---
Field Meaning
1 Minute (0-59)
2 Hour (2-24)
3 Day of month (1-31)
4 Month (1-12, Jan, Feb, ...)
5 Day of week (0-6) 0 = Sunday, 1 = Monday, ... or Sun, Mon, etc)
6 Command to execute
Some versions of cron allow an extra field before the command to
specify the user that the command will run as.
---
35 2 * * * root tar czf /usr/local/backups/daily/abc.tar.gz /abc >/dev/null 2>&1
This will run tar czvf /usr/local/backups/daily/abc.tar.gz /abc at 2:35am every day.
The > /dev/null 2>&1 part means to send any standard output to /dev/null and
to redirect standard error (2) to the same place as the standard output (1).
Basically it runs the command without any output to a terminal.
Permalink: Schedule A Unix Cron Job
Trackback: http://publish.creative-weblogging.com/publish/mt-tb.pl/35794
Mr Wong
Vote for Schedule A Unix Cron Job:
|
Rating: 5.50 out of 2 vote(s) cast.
|
Subscribe
Use the search to look for other interesting posts
| RSS | See all blog subscribe options |
|
What is RSS? | |
| Yahoo! |
|
| Addthis |
|
| Bloglines |
|
| Newsletter | |
| Follow us on Twitter! |










