Useful crontab short cuts

While reading through crontab(5) this morning I came across this useful nugget of information:

“These special time specification “nicknames” are supported, which replace the 5 initial time and date fields, and are prefixed by the @ character:

@reboot : Run once, at startup.
@yearly : Run once a year, ie. “0 0 1 1 *”.
@annually : Run once a year, ie. “0 0 1 1 *”.
@monthly : Run once a month, ie. “0 0 1 * *”.
@weekly : Run once a week, ie. “0 0 * * 0”.
@daily : Run once a day, ie. “0 0 * * *”.
@hourly : Run once an hour, ie. “0 * * * *”.”

So instead of writing:

0 * * * * command

You can specify hourly to accomplish the same thing:

@hourly command_to_run

Or if you want to run something when a machine is rebooted you can add this:

@reboot echo “” | mail -s “`/bin/hostname` was recently rebooted” root

Several of these short cuts are rather handy and it makes things easier to read IMHO. Gotta love short cuts!

4 thoughts on “Useful crontab short cuts”

  1. @reboot is a misnomer. It means whenever crond is started.

    We have a puppet manifest that will restart crond whenever puppet changes the timezone. When that happened, the @reboot crontabs all fired.

Leave a Reply

Your email address will not be published. Required fields are marked *