How to restart centos 6 server from cron

FabricioG asked:

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?

My answer:


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.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.