Structure of a cron job:
A
cron job contains six fields.
* *
* * *
a_ command_to_execute
| | | | |
| | | |
+------- day of week (0 - 6)
(0=Sunday)
| | | +---------
month (1 - 12)
| | +----------- day
of month (1 - 31)
| +------------- hour (0
- 23)
+--------------- min (0 -
59) |
A crontab example:
# Execute script "/home/user/forwardmail"
every minute of every day
*
* *
* *
/home/user/forwardmail
# Execute script "/home/user/trim.sh"
every 5 minutes
*/5 *
* *
*
/home/user/trim.sh
# Execute script "/home/user/archive.pl"
at 12:00 AM every day
0
0 *
* *
/home/user/archive.pl
# Execute script "/home/user/bkup.pl"
at 3:30 AM every Sunday
30
3 *
* 0
/home/user/bkup.pl
# Execute script
"/home/user/email-july4th-special.php"
on July 4th at
# 12:00 AM
0
0 4
7 *
/home/user/email-july4th-special.php
|
Ignoring cron job command
output:
Cron jobs send an email to the
user executing the cron job. If this
is not needed, place
>/dev/null
2>&1 at the end of the
command.
30 3
* *
0
/home/user/bkup.pl
>/dev/null
2>&1 |
Send command output to a log
file:
Use
>>/home/user/cronlog.txt to
add the output of the command
to the end of the /home/user/cronlog.txt
file.
30 3
* *
0
/home/user/bkup.pl
>>/home/user/cronlog.txt |
If you want to overwrite the
previous output, use
>/home/user/cronlog.txt
30 3
* *
0
/home/user/bkup.pl
>/home/user/cronlog.txt
|
|