0

I wish to run stuff from startup and also trigger reboots using cron.

I was using sudo crontab -e and adding commands there. The commands work apart from the reboots. The reboots do not happen all the time. I wish to reboot at 4 am every morning. My added line is :

00 4 * * * root /sbin/shutdown -r now >> /var/log/daily-backup.log 2>&1

I now instead modified /etc/crontab instead for the reboots and it seems to work. Why is this? Shouldn't crontab -e work anyways because commands get run as root?

0

1 Answer 1

3

If you do crontab -e then you're modifying the per user cron entry, typically in /var/spool/cron/crontabs/$USERNAME.

Because these are per-user, they don't have the requirement for a username.

So the entry would look something like

00 4 * * * /sbin/shutdown -r now >> /var/log/daily-backup.log 2>&1

In contrast, the /etc/crontab (and files in /etc/cron.d/) are sytem crontab entries, and so require a username.

You can see what cron is doing by looking at /var/log/syslog (on Debian; /var/log/cron on RedHat). If your job is being called then there should be a line in your daily-backup.log... potentially saying that it can't find the "root" command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.