This simple tutorial show how you can shutdown your Linux computer automatically after a download (torrents as well as direct) is finished or a task is completed.
Last day I posted about how to get email alerts of downloads’ progress going at your home computer and promised to come up with more interesting stuff like this. So here I am, and in this post I will tell you how you can shutdown your Linux computer when a download finishes. Note this also applies for direct downloads or the downloads going on via torrents. You can also use this trick to shut down your PC after installation of a file has been done. I will show you two ways of doing this, one via a script and second via an application. Basically, the script can be used to shutdown your PC after finishing of any task, while the application has more parameters to shut your PC down.To shutdown your computer via a script, we go our usual way of creating the script first, say tasks.sh. Then we write the commands we wish to execute in it one after the other, and at last we issue the shutdown command or init 0. When we execute the script, all the tasks we listed are done one after the other and when all the tasks are done, the computer shutdowns. Here is the simplest example of shutting down your PC after a download is done.
wget http://www.example.com/file1.tar.gz init 0
In the above example, wget, the file downloader will download the file1.tar.gz from example.com and after its done, it will shutdown the PC automatically via the init 0 command. Please note that you need to be superuser to shutdown or reboot your PC via the command line, so you have to execute this script as root.
Using this script, you can shutdown your PC after completion of *any* command-line tasks. Just make sure you add the init 0 command at the end and run this script as the super user. E.g. to shutdown your PC after an installation has been completed, use:
apt-get install package
You can also list more than one tasks in tasks.sh file one after the other, in order you wish them to get executed. To learn more how to create such scripts and how to make them executable, consider reading my previous article.
The above process has certain limitations, e.g. it can be used only for command line task and shutting down the PC after direct downloads. For shutting down your PC after torrent downloads, or using GUI downloaders, I use an KDE application called Sentinella. You can use this application in other desktops like Gnome too, provided you have necessary libraries installed.
Use you package manager to install it. Arch Linux users will have to get it from AUR as its not available in official repositories yet.
The program is very powerful and can do a lot of tasks such as shutting down, rebooting. playing an alarm, executing a command, putting the PC to sleep mode or terminating a program depending on the activity of computer.
To shutdown your PC after a download (torrent or direct) is done, click on Network Traffic, select download is lower than 3KBps, or a speed you prefer on the interface you use to connect the internet during a specified period of time (say 5 minutes) and select the action “Shutdown”. Don’t forget to save your settings by clicking the start button. The application will hide itself in the notifications tray and will monitor the system activity. The moment download gets lower than the speed you specified for specified number of minutes (indicating end of download), it will shut the system down. Note that this app can be used for more actions, not just shutting down your PC at end of download, I leave it to you to discover more.