Scheduling tasks with cron
Cron is used to automate periodic tasks. You can simply copy scripts in cron directories under /etc/cron.hourly, daily, weekly or monthly to run it at these specific intervals.
If you need finer control, as a user you can run cronstab -e which allows you to edit your own configuration file using vi. This file is stored in /var/spool/cron/crontabs/ under your user name.
The syntax of a cron file looks like:
1 2 3 4 5 /path/script args
Where:
1: minutes (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 or January, February, ... 0 and 12=December)
5: Day of the week(0-7 or Monday, Tuesday, Wednesday, ... 0 and 7=Sunday)
You can also use wildcards:
*: applies everytime 1-4: start if 1,2,3 or 4 matche 1-4/2 step-by-step, here: 1 and 3 1,5,6: enumeration */3: every third 1-4,10-15: enummeration and range combined
Examples:
# every 10 minutes */10 * * * * /etc/job # on weekdays at 19:00 0 19 * * 1-5 mail -s "It's 7pm watch TV"
Leave a Reply
You must be logged in to post a comment.