Special cron entries

05 May 2015 in Tech

There are some special entries that can be used when creating a crontab entry (crontab -e), most of which are just shortcuts for the standard crontab entries that we all know and love.

You can use them in your crontab just like you would a normal entry:

# m h dom mon dow command
# Say hello each time the machine boots up
@reboot echo 'Hello world. I just booted up'
# Say Happy new year, using both forms of entry
@yearly echo 'Happy new year'
0 0 1 1 * echo 'Happy new year from me too'

The @reboot entry could be useful for keeping track of when a machine is rebooted. Just add the crontab and each time the machine restarts you'll get an email with any output from the crontab (in this case, "Hello world. I just booted up")

Possible entries

There are nine possible aliases, some of which are just aliases for each other (such as @yearly and @annually)

EntryDescriptionEquivalent Entry
@rebootRun once, at startupNone
@yearlyRun once a year0 0 1 1 _
@annuallySame as @yearly0 0 1 1 _
@monthlyRun once a month0 0 1 * _
@weeklyRun once a week0 0 _ _ 0
@dailyRun once a day0 0 _ * _
@midnightSame as @daily0 0 _ * _
@hourlyRun once an hour0 _ * * *

I'm not sure I'd recommend using any of these (except maybe @reboot) as the standard syntax is well known by anyone that should be editing a crontab, but it's interesting to know that there are aliases in there for common time periods.

(via mkaz (now offline))