5

Information

I have the following crontab for the root user on Debian 10.

root@debian:~# crontab -l
# crontab comments curtailed for serverfault
#
# m h  dom mon dow   command

30 3 * * * shutdown -r now

If I run uptime and who -b I get the results of the last time I did a manual reboot (yesterday around 6pm).

root@debian:~# uptime
 11:03:19 up 16:29,  1 user,  load average: 0.00, 0.01, 0.00
root@debian:~# who -b
         system boot  2020-12-26 18:34

I created the crontab around 7pm yesterday, so it was definitely in place prior to the target time.

Question

Is there a reason why this may not have worked? Can I debug this in any way?

Geesh_SO
  • 165

1 Answers1

4

Check the log to see if the cron job run at the specified time.

On Debian cron is logged in /var/log/syslog, see it there is any error reported if the cron job was activated.

If you do grep cron /var/log/syslog is there anything logged at the time cron was suppose to do reboot?

Also check if cron service is running, if you do systemctl status cron.service does it say the service is active and enabled. Cron service needs to be running in order for cron jobs to run.

It could also be an issue with cron not being able to find shutdown command, try using /usr/sbin/shutdown -r now in cron.

For Debian 12 and newer

The traditional log files have been replaced by systemd-journald in Debian 12, so you can't search in /var/log/syslog using tools line grep any more. This also affects other GNU/Linux Distributions. But you can use journalctl instead and also filter the logs directly there:

journalctl -u cron
Lion
  • 548
ralz
  • 2,861
  • 3
  • 19
  • 23