How to use @reboot in /etc/cron.d
Olivia Zamora
I am migrating individual user's crontabs to /etc/cron.d, as that would allow proper backup, restore and versioning.
So far, as I understand the only difference between user's crontabs and the etc ones is that you have to specify the user as the 6th column. Is this right?
And my main question, for which I couldn't find the answer anywhere on the internet:
What is the right way to use @reboot in /etc/cron.d or /etc/crontab?
something like @reboot root command?
3 Answers
From the crontab man page:
Jobs in /etc/cron.d/
The jobs in cron.d are system jobs, which are used usually for more than one user. That's the reason why is name of the user needed. MAILTO on the first line is optional.
EXAMPLE FOR JOB IN /etc/cron.d/job
#login as root #create job with preferred editor (e.g. vim) MAILTO=root * * * * * root touch /tmp/fileThat's the whole section about crontab in /etc, so I guess the inclusion of the user under whose name the job runs is indeed the only difference.
Again from the same man page:
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 after reboot.
Thus your inference that the proper way to use @reboot is
@reboot user_name commandis correct.
If you're running it interactively as below, you don't specify the user:
crontab -e
@reboot /root/mycommandIf you're putting it as a file in /etc/cron.d, e.g. /etc/cron.d/mycronfile, you need to put the user:
@reboot root /root/mycommand In case of /etc/crontab you just have to add these lines.
@reboot command
Where command can be any script or a single file.
2