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?


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

In case of /etc/crontab you just have to add these lines.

@reboot        command

Where command can be any script or a single file.

  • Does that work? /etc/crontab usually requires a user name. – mwfearnley Apr 9 '19 at 9:57
  • @mwfearnley yes, it looks like a username is needed in the /etc/crontab file, even with reboot. Without "root" I got in "service cron status" the following message "Apr 20 17:59:11 movefiles cron[998]: Error: bad username; while reading /etc/crontab". After I changed the line to "@reboot root date >> ~/date.txt" it worked. – masterxilo Apr 20 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.