Crontab: Difference between revisions
Created page with "Cron is the name of program that lets you execute commands or scripts automatically at a specified time/date. Crontab is the program to mange cron jobs. == References ==..." |
No edit summary |
||
Line 1: | Line 1: | ||
Cron is the name of program that lets you execute commands or scripts automatically at a specified time/date. Crontab is the program to mange cron jobs. | Cron is the name of program that lets you execute commands or scripts automatically at a specified time/date. Crontab is the program to mange cron jobs. | ||
<code>crontab -e</code> Lets you edit cron jobs for the current user (You can use su to switch users to manage their cron jobs.) | |||
Each line has five time-and-date fields, followed by a command, followed by a newline character ('\n'). The fields are separated by spaces. The five time-and-date fields cannot contain spaces. The five time-and-date fields are as follows:<br /> | |||
<br /> | |||
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday). | |||
<br /> | |||
<br /> | |||
<code>01 04 1 1 1 /usr/bin/somedirectory/somecommand</code> | |||
The above example will run /usr/bin/somedirectory/somecommand at 4:01am on January 1st plus every Monday in January. | |||
<br /> | |||
<br /> | |||
An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used | |||
<code>01 04 * * * /usr/bin/somedirectory/somecommand</code> | |||
The above example will run /usr/bin/somedirectory/somecommand at 4:01am on every day of every month. | |||
<br /> | |||
<br /> | |||
You may want to run a script some number of times per time unit. For example if you want to run it every 10 minutes use the following crontab entry (runs on minutes divisible by 10: 0, 10, 20, 30, etc.) | |||
<code>*/10 * * * * /usr/bin/somedirectory/somecommand</code> | |||
<br /> | |||
<br /> | |||
Cron also offers some special strings, which can be used in place of the five time-and-date fields: | |||
String Meaning <br /> | |||
<br /> | |||
@reboot Run once, at startup.<br /> | |||
<br /> | |||
@yearly Run once a year, "0 0 1 1 *".<br /> | |||
<br /> | |||
@annually (same as @yearly)<br /> | |||
<br /> | |||
@monthly Run once a month, "0 0 1 * *". <br /> | |||
<br /> | |||
@weekly | |||
Run once a week, "0 0 * * 0". | |||
@daily | |||
Run once a day, "0 0 * * *". | |||
@midnight | |||
(same as @daily) | |||
@hourly | |||
Run once an hour, "0 * * * *". | |||
Revision as of 20:11, 14 January 2017
Cron is the name of program that lets you execute commands or scripts automatically at a specified time/date. Crontab is the program to mange cron jobs.
crontab -e
Lets you edit cron jobs for the current user (You can use su to switch users to manage their cron jobs.)
Each line has five time-and-date fields, followed by a command, followed by a newline character ('\n'). The fields are separated by spaces. The five time-and-date fields cannot contain spaces. The five time-and-date fields are as follows:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday).
01 04 1 1 1 /usr/bin/somedirectory/somecommand
The above example will run /usr/bin/somedirectory/somecommand at 4:01am on January 1st plus every Monday in January.
An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used
01 04 * * * /usr/bin/somedirectory/somecommand
The above example will run /usr/bin/somedirectory/somecommand at 4:01am on every day of every month.
You may want to run a script some number of times per time unit. For example if you want to run it every 10 minutes use the following crontab entry (runs on minutes divisible by 10: 0, 10, 20, 30, etc.)
*/10 * * * * /usr/bin/somedirectory/somecommand
Cron also offers some special strings, which can be used in place of the five time-and-date fields:
String Meaning
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly
Run once a week, "0 0 * * 0". @daily
Run once a day, "0 0 * * *". @midnight
(same as @daily) @hourly
Run once an hour, "0 * * * *".