Crontab: Difference between revisions

From Psygen Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 30: Line 30:
<br />
<br />
@reboot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once, at startup.<br />
@reboot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once, at startup.<br />
<br />
@yearly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a year, "0 0 1 1 *".<br />
@yearly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a year, "0 0 1 1 *".<br />
<br />
@annually &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (same as @yearly)<br />
@annually &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (same as @yearly)<br />
<br />
@monthly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a month, "0 0 1 * *". <br />
@monthly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a month, "0 0 1 * *". <br />
<br />
@weekly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a week, "0 0 * * 0".<br />
@weekly
@daily &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once a day, "0 0 * * *". <br />
@midnight &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (same as @daily)<br />
Run once a week, "0 0 * * 0".
@hourly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run once an hour, "0 * * * *". <br />
@daily
Run once a day, "0 0 * * *".
@midnight
(same as @daily)
@hourly
Run once an hour, "0 * * * *".  





Revision as of 20:12, 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 * * * *".


References

  1. Cron How To