Created
December 3, 2011 17:28
-
-
Save icemancast/1427641 to your computer and use it in GitHub Desktop.
setup cron job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ crontab -e | |
crontab -e Edit your crontab file, or create one if it doesn’t already exist. | |
crontab -l Display your crontab file. | |
crontab -r Remove your crontab file. | |
crontab -v Display the last time you edited your crontab file (This option is only available on a few systems.) | |
* * * * * command to be executed | |
- - - - - | |
| | | | | | |
| | | | +----- day of week (0 - 6) (Sunday=0) | |
| | | +------- month (1 - 12) | |
| | +--------- day of month (1 - 31) | |
| +----------- hour (0 - 23) | |
+------------- min (0 - 59) | |
Notes | |
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported. | |
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed . | |
4. Crontab Example | |
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM. | |
30 18 * * * rm /home/someuser/tmp/* | |
min hour day/month month day/week Execution time | |
30 0 1 1,6,12 * – 00:30 Hrs on 1st of Jan, June & Dec. | |
0 20 * 10 1-5 –8.00 PM every weekday (Mon-Fri) only in Oct. | |
0 0 1,10,15 * * – midnight on 1st ,10th & 15th of month | |
5,10 0 10 * 1 – At 12.05,12.10 every Monday & on 10th of every month | |
6. Disable Email | |
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line . | |
>/dev/null 2>&1 | |
7. Generate log file | |
To collect the cron execution execution log in a file : | |
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment