![]() |
version seven.   http://demongin.org |
Stupid Linux Tricks: cron Task @reboot
A blurb about using the arrobe to write special cron tasks
Sunday, 2010-03-28 | AlmostEffortless, Careerism
A little known fact of cron is that you can use it to execute commands as soon as your machine returns from a reboot. If, for example, I create a file in /etc/cron.d/ called "whatever" that looks like this:
@reboot root `which sshfs` user@remotemachine:/mnt/data /mnt/data
The above command will be executed once the system is fully booted. This is ideal for cases in which depend on a number of services or in which manual intervention is required. One could, for example, create a file called "whatever" in /etc/cron.d/ to remind him that he needed to manually intervene once the boot process was finished and that he was now free to do just that:
@reboot root echo "Don't forget the sshfs mount!" | mail -s "[`hostname`] Reboot!" root
There are a handful of other, similarly useful shortcuts that Vixie built into cron but that aren't particularly well known:
@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 * * * *".
(Excerpted from the man page)
