Question

Ubuntu cron job reboot every 4 hours

My experience level is low on unbuntu. I install, config and run website. I want to make my ubuntu reboot every 4 hours. from 4 in 4 hours, non stop.

Please tell me the commands i need to send. Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
June 14, 2016
Accepted Answer

You can set your server to reboot every 4 hours by setting the following crontab.

First you may want to select your preferred editor otherwise vi maybe a tad too complex for someone just starting. To that first:

sudo update-alternatives --config editor

Then edit your crontab:

sudo crontab -e

There you can set your server to reboot every 4 hours with the following:

# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command  

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

However, you should not have a need to reboot your server every 4 hours. If you are running into that then you have a larger issue that needs to be investigated. Perhaps you have a memory leak, or something else on your server is overloaded.

You should be able to run a server for months without any service interruptions. Technically years, however you will need to reboot for a security update.

I edited file for auto reboot Ubuntu 18 server in every 6 hours. Is that ok?

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

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

It’s not working for me, on Ubuntu 18.04…

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.