[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2269
  • Last Modified:

On Ubuntu how do I use CRON to reboot my server automatically every night at midnight?

Hi all,

I have a ubuntu 14.04 x64 distribution on a Linode VPS with Apache 2.4.7 and mySQL server 5.5.

I would like to be able to reboot my server automatically every midnight (GMT - my server date is set to GMT).

Could anyone please assist? I have no experience with CRON or .sh scripts and I have only started using linux last month.

thanks in advance
1 Solution
Enter the following command to edit the crontab file:

sudo crontab -e

Add the following line:

0 0 * * * reboot


0 0 * * * shutdown -r now
Manfred BertlManagerCommented:
I dare to ask: why would you have a need to restart your server every day? I think, thats one of the strenghts of Linux, that it is very stable and you don't have to restart things on your server. The goal of a server, IMHO, is, that it runs 24/7 with no downtime. So, a reboot would cause also a few minutes downtime.
Sandeep KhanagwalCommented:
Add the line in the end of your Crontab file. It will reboot your server in midnight as per your vps time.

@daily shutdown -r now

Save file and reboot crontab .

For further reading / detail about crontab use the below link .

I 2nd mbertl's concern.  There is no good reason to be rebooting a server every night anymore.  If you are having problem's with apache or MySQL, you should be fixing those instead of rebooting.

Also, while it makes little difference today, if you have an older server you should only use the reboot command in single user mode, as it sent a sigkill.  The init command gracefully exited the processes in the reverse order that they were started.  In newer Redhat you should use systmctl to reboot.
badwolfffAuthor Commented:
Thanks for all the advice and the working code guys. I tried the code and it works but I turned the task off for now.
I use linode and I just upgraded to the next best service they have on offer. It costs me 10$ extra every month but no more problems related to running out of resources.

I was trying to patch things up but as you guys pointed out, the whole point of using linux is that rebooting should be used as a last option since the server has hardly ever crashed since I began using it. So I went to the source of the problem: too many sites using up all the resources. Got more resources, all sorted :)

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now