Special cron entries

This article was published 4 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

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))

Thoughts on this post

Leave a comment?