3

I've run

crontab -e

and added this line to crontab to reboot my machine every morning at 1am.

0 1 * * * root /sbin/shutdown -r now

When crond runs I see this in my logs

Aug 20 01:00:01 stc-logs CROND[30791]: (root) CMD (root /sbin/shutdown -r now)

but, the system does not reboot.

Any ideas?

-Craig

  • 1
  • Do you have SELinux enabled and is auditd running? Any denies in /var/log/audit/audit.log ? – Aaron Aug 20 '15 at 17:03
  • 1
    @Michael Hampton: I don't understand. My question is quite clear in the title "How do I schedule a recurring reboot in CentOS 6.7?" and the body contains what I have tried so far. – Albion Aug 20 '15 at 17:31
  • The problem is that you should not be rebooting on a schedule at all. You have a different problem that you should fix. – Michael Hampton Aug 20 '15 at 17:35
  • 1
    @MichaelHampton While I generally agree rebooting servers shouldn't be a standard operating procedure, I also think this is no reason to answer a well-posed technical question ("why this configuration doesn't work?") with "you just shouldn't be doing this". The purpose of this site is answering technical questions, and although questioning the rationale behind them can and should be done, it sometimes gets a bit too aggressive (not your case, but it does indeed happen). – Massimo Aug 20 '15 at 17:50
7

You're using the syntax for an entry in /etc/crontab which has the user ID in the 6th column, but if you use crontab -e, you're editing the entry in /var/spool/crontab, which does not have this column since they are already separated per user.

In other words, this is what you would put in /etc/crontab:

0 1 * * * root /sbin/shutdown -r now

And this is what you should enter when doing a crontab -e (assuming you're root, otherwise it won't work)

0 1 * * * /sbin/shutdown -r now

In other words, you are now trying to execute the command 'root', which to my knowledge does not exist.

  • It actually does work in centos, provided you are putting this in the root crontab. (specifying the user) crontab -l|tail -n1; ls -al /tmp/id.txt * * * * * root id > /tmp/id.txt -rw-r--r--. 1 root root 0 Aug 20 18:01 /tmp/id.txt In CentOS 6, see man 5 crontab – Aaron Aug 20 '15 at 18:00
  • I think the term "root crontab" is ambiguous in this case. Do you mean /var/spool/crontab/root or /etc/crontab? They do have different syntax according to the crontab manual page and the question posted. The manual calls /etc/crontab a "system crontab" (with 6th column). – JvO Aug 20 '15 at 18:09
  • They have become interchangeable. I assume this was to prevent confusion between the two methodologies or standards, but I have not read through the change logs to validate the reasoning for the behavioral change. – Aaron Aug 20 '15 at 18:17
  • 1
    Well, whatever the functionality, this solution solved my problem. As soon as I removed the sixth column from my root user crontab the server started to reboot. I was also able to get the system to reboot while using the sixth column in the system crontab (/etc/crontab). Thanks!! – Albion Aug 20 '15 at 18:29

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.