We have already learned how to automatically wake up your Linux system from sleep or hibernation mode. It was quite useful when you don't want your system to function all day. You can simply put it in sleep mode and wake it up automatically at a specific time. Today, we will be discussing a yet another similar topic which describes how to auto shutdown, suspend, hibernate your Linux system at a specific time. We can do it in two different methods. We will show them both.
Auto Shutdown, Reboot, Suspend, Hibernate Your Linux System At A Specific Time
I have tested this guide on Ubuntu 16.04 desktop. However, these method probably will work on other Linux distributions.
Method 1 - Using Autopoweroff
Autopoweroff is simple, yet useful utility which is used to poweroff, reboot, suspend, hibernate your Linux machine, or run any custom command provided by the user at a specific time. On good thing about Autopoweroff is it will shutdown the system only when certain conditions are met. If the system we intended to shutdown is being accessed/used by another system, Autopoweroff utility won't shutdown it. Let us say you have set shutdown time at 12:00am, but some other systems on your network are still accessing it after 12:00am, then it will not shutdown. It will wait for the other systems to complete their work, and shutdown itself only if no other computer on the network is responding to ping. Sounds pretty useful, isn't it?
Your system will shutdown, suspend, or hibernate when the following conditions are met:
- Any hosts that the computer is dependent on is not answering ping anymore.
- No keyboard or mouse activity has been detected on the computer for a while.
- And of course, the user has not disabled Autopoweroff.
Autompoweroff should work on any modern Linux operating systems, and is free and open source. So, anyone can fork, improve the code, or add any additional features they want.
Download the latest Autopoweroff installer file for your distribution. Currently, It is available as .deb and .rpm packages.
I use Ubuntu, so I downloaded the .deb file.
$ wget https://github.com/deragon/autopoweroff/releases/download/3.0.0/autopoweroff-3.0.0-1.noarch.deb
Then, install it using commands:
$ sudo dpkg -i autopoweroff-3.0.0-1.noarch.deb
$ sudo apt-get install -f
Once installed, open GUI configuration tool or /etc/autopoweroff.conf file and edit to your particular needs.
Here, let us follow the GUI method. Open up Autopoweroff GUI configuration tool either from the the Menu or Unity dash.
This is how Autopoweroff configuration window looks like.
As you can see in the above screenshot, Autopoweroff utility has two sections namely Status & Commands, and Configuration. In Status & Commands section, you can enable or disable the options such as auto shutdown, suspend, reboot, and hibernate.
In Configuration section, you can set the time to run a particular action at a specific time.
The configuration section has further split into three columns. In the first column, you can define the period and timeouts settings.
- Start hour - Start hour of the 'no action' interval. Autopoweroff will run the action such as poweroff, suspend, reboot, hibernate or other only outside the (Start hour, End hour) interval.
- End hour - End hour of the 'no action' interval. Autopoweroff will run the action such as poweroff, suspend, reboot, hibernate or other only outside the (Start hour, End hour) interval.
- Idle time - It is the time required by Autopoweroff to wait for idle user interactively (keyboard, mouse, joystick... etc) before proceeding to any action. Thus if Autopoweroff finds itself outside the 'no action' interval, the action would still not be executed as long as there is user activity on the computer + 'idle time' delay.
- Boot delay - It is the minimum delay that Autopoweroff must wait before running any action if Autopoweroff was started during a shutdown interval. This prevents accidental shutdown to occur if Autopoweroff was unexpectedly started; it gives time for users to kill Autopoweroff.
In second column, you can add, remove, or edit dependent systems with their hostname or ip address. In third column, you can select the actions that needs to be performed at a specific time. Your system will poweroff, sleep, hibernate, or execute any custom command based on the inputs you've given in the Configuration section. You need to be careful in this section. Any misconfigured settings will cost you data loss or unwanted/unexpected shutdown or reboot.
Once you made the changes, click Save to apply the changes. You can undo the changes by clicking the Revert button. To close this utility, simply press Quit button.
For more details, refer Autopoweroff GitHub page.
Method 2 - Using qshutdown
qshutdown is yet another utility to auto shutdown, reboot, suspend, and hibernate your system at a specific time. It works well on Ubuntu, Linux Mint and other Ubuntu variants such as Kubuntu, Xubuntu, Lubuntu, etc.
To install it on Ubuntu and its derivatives, run the following commands one bey one in your Terminal:
$ sudo add-apt-repository ppa:hakaishi/qshutdown
$ sudo apt update
$ sudo apt install qshutdown
Once installed, launch it either from Unity dash or Menu.
This is how qshutdown interface looks like in my Ubuntu 16.04 LTS desktop.
As you can see in the above screenshot, qshutdown doesn't have much options. There are only few settings. If you want to perform any action (shutdown/reboot/suspend/hibernate) in your system in 60 minutes from now, just choose "Minutes till shutdown" option and enter the time. Then, click OK.
Once you hit the OK button, the countdown time will start, and the selected action will be performed at the exact time.
If you want to show the warnings before the selected action takes place, check the box that says "Warnings on".
To schedule your action at a specific time, choose "Shutdown-time" and enter the exact time to perform the selected action.
As you see in above screenshot, I want my system to shutdown at 4:40pm. You can choose any other action of your choice.
Another good thing is we can schedule the actions weekly. To do so, click Calendar, and go to Weekly option. There you can choose action you want to perform on a specific day of the week.
The qshutdown program is very simple, yet fully functional and useful utility. Unlike Autopoweroff, qshutdown will shutdown, suspend, hibernate your system as soon as it reached the deadline, even if one of your other systems are accessing it. So, you must be very very careful while doing any remote jobs.
For more details, refer qshutdown launchpad page.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
Seemed like a good utility (autopoweroff)since my Unity Ubuntu 18.3.4 won’t go to suspend on it own. But it did not work. No GUI showed up and I tried to edit the autopoweroff config file but gedit wouldn’t cooperate. Gave up and removed the files.
I’m having good results with qshutdown on Linux Mint. Thanks for article.
Glad I could help.