How to use @reboot in /etc/cron.d

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/file

That'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 command

is correct.


If you're running it interactively as below, you don't specify the user:

crontab -e
@reboot /root/mycommand

If 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

Tags:

Linux

Cron