Setting a Crontab
Syntax:
* * * * * command
# Use the hash sign to prefix a comment
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
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/*
Changing the parameter values as below will cause this command to run at different time schedule below :
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 |
: |
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
No comments:
Post a Comment