Last Updated:

Shutdown Ubuntu 18.04 Automatically

Categories Computing, Ubuntu

I recently made my own Home Entertainment System using Ubuntu Bionic Beaver (18.04 – more on this in later posts) with PLEX, and have a need to shut it down at midnight every night. There are many ways and many utilities to help with this, but since it is a server, we want to keep the overheads as low as possible so that it can dedicate as much resource as possible to serving media files. Luckily the bog standard linux ‘shutdown’ command has its own embedded scheduler.

Running a CRON job is unnecessary because as written above the shutdown command has its own scheduler.

Downloading fancy GUI utilities is also an unnecessary overhead on the system. So what’s left is the simple shutdown command that only needs to be placed in a startup script. There are many, and the last one to be executed at system startup is the RC.LOCAL.

The RC.LOCAL script should be in your /etc folder. In some installations, it can be in the /etc/rc.d folder. However, in Bionic Beaver (Ubuntu 18.04) it may not be present at all. If this is the case then no problem, all we have to do is create it in the /etc folder:

 sudo nano /etc/rc.local 

The default content should look something like this. If it doesn’t exist and you need to create it then this is the default:

 #!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
exit 0 

So all we need to add to it is the shutdown command:

shutdown -h 00:00

Add this BEFORE the exit 0 command.

So now we have the simplest way of shutting down our system everyday at midnight.

Lastly we need to make sure the script is executable:

 sudo chmod +x /etc/rc.local 

If, however, we need to cancel the shutdown then all we need to do is issue the following at the command line:

shutdown -c

This is the most resource effective way of scheduling a shutdown at the same time everyday.

Please let me know if you have an even simpler method, or would like to leave any feedback.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.