I realize this is frowned upon. Many will suggest they don't recommend doing a server restart from cron because it's not being monitored. In my case I would like to do this, the reason is because the server is used for only one task, in a node server environment. The server runs out of memory and I've been advised to just restart the whole server. I'm ok with this.

Currently in my cron file I have the following. (I got this off another stack question) .

0 */4 * * * /usr/bin/reboot

However it doesn't work. When I manually go to this directory /usr/bin/ then type "reboot" it works. But executing like this /usr/bin/reboot from chron doesn't restart the server.

When I do ls /usr/bin/reboot the return is /usr/bin/reboot When I do which reboot the return is /sbin/reboot

How would I restart the server on centos 6 using cron?

  • Thanks for commenting. How is the answer posted related to this? I'm trying to restart the server from cron. The answer marked as duplicate is how to restart cron, not the server. @MichaelHampton – FabricioG Jun 21 at 17:48
  • "When I manually go to this directory /usr/bin/ then type "reboot" it works. " Things do not work like you think, or at least in general. Without a path, the shell looks at the $PATH variable to find out where is the command you are trying to execute. So reboot may well be somewhere else. Do ls /usr/bin/reboot and if you get an error you have your explanation on why it does not work. Try which reboot to find out where it is really. Remember also that in theory maybe only root can use it so it has to be in root's crontab. – Patrick Mevzek Jun 21 at 17:54
  • ls /usr/bin/reboot returns this: ls /usr/bin/reboot /usr/bin/reboot which reboot returns this: /sbin/reboot @PatrickMevzek – FabricioG Jun 21 at 17:57
  • 1
    I updated with a brief description of why. I had put what I did because on another question it became more a lecture of why you shouldn't restart from cron., but thanks for the heads up! @PatrickMevzek – FabricioG Jun 21 at 18:06
  • 1
    If your web app has a memory leak, then that's what you need to restart. At least until the developer fixes it. Reboting the whole machine doesn't make sense in this context. – Michael Hampton Jun 21 at 18:20

As a commenter mentioned, you're calling the wrong program. The reboot binary is at /sbin/reboot, not at /usr/bin/reboot. The latter is a symbolic link to consolehelper, which is a wrapper that lets non-root users run the corresponding program in /sbin under certain circumstances. You can see its man page if you're really interested in how it works, but as CentOS 6 will go end of life soon, and current versions do not use it, it's probably not worth worrying about. Just put in the correct path and go on to more important things, like fixing the memory leak.

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.