How to schedule tasks with Cron
Introduction
cron runs a command on a schedule. Output is mailed to the crontab owner unless you redirect it.
Adding Cron Jobs
Cronjobs can provide you a time accuracy of 5 points,
Minute of the hour 0 - 60
Hour of the day 0 - 23
Day of the month 1 - 31
Month of the year 1 - 12
Day of the week 0 - 7
The syntax of a cron job is as shown below.
MIN HOUR DOM MON DOW CMD
A sample cronjob to run on every tuesday 2.30am every month will be like shown below.
30 2 * * 2 CMD
* is used to represent all for that corresponding field.
Service Options.
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
Tips
List users cronjobs:
crontab -l -u <user_name>
Edit users cronjobs:
crontab -e -u <user_name>
List user cronjobs from the user’s shell:
crontab -l
Edit user cronjobs from the user’s shell:
contab -e
Clear all cronjobs for user:
crontab -r
Cronjob to run every 2 hour:
0 */2 * * *
Please use the / character to specify the repetition interval */5 for every 5, can be used in any fields like minute hour day etc
Cronjob to run 2,3,4,5,6,7 hours
0 2-7 * * *
Please use the - character to specify the range, 2-7 is same as 2,3,4,5,6,7, can be used in any fields like minute hour day etc
Cronjob to run every minute
* * * * *
From the EuroVPS FAQ.
More in how toYour next infrastructure partner
Still have
a question?
Tell us what you are trying to do. An engineer will read it and reply.
+357 222 32280
who will look after your infrastructure.
Let’s start with your setup.
A little context helps us start the right conversation.
