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

Posted on 2014-08-31
Last Modified: 2014-09-03
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
Question by:badwolfff
    LVL 23

    Accepted 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
    LVL 4

    Expert Comment

    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.
    LVL 3

    Expert Comment

    by:Sandeep Khanagwal
    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 .
    LVL 27

    Expert Comment

    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.

    Author Comment

    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

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now