Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I usually start a download before I go to school.
Which command should I use to automatically make the necessary saves and turn off the computer after a particular task has been completed?
(Say, after installing the updates, or after downloading a large file.)

I have also cross-posted at askubuntu.

share|improve this question

5 Answers 5

It depends you started task. If it is some command line tool you could simply run halt or shutdown -h now:

  1. wget http://..../somelargefile; halt - halt will be executed after wget

  2. wget http://..../somelargefile && halt - halt will be executed if wget return no errors

  3. wget http://..../somelargefile || halt - halt will be executed if wget return errors

Alternative to this is using kshutdown - in this app you can specify what action should be done (reboot/shutdown/hibernate/etc or command execution) and when (after some time or when another application exits). If you want to use this tool you need to chose correct process - some update utilities starts few subprocesses.


share|improve this answer
You can also give shutdown a time to wait; no need to use kshutdown for that purpose. –  Jefromi Nov 30 '10 at 17:47
No, but shutdown doesn't have any way of waiting for an actual event. –  Shadur Oct 31 '11 at 9:19

Every process has a directory named according to its process id (pid) in the proc filesystem. Therefore you can wait for a specific process' termination by checking whether its directory exists repeatedly.

You can use this to perform a system shutdown after process termination like this (replace 2296 by the pid to wait for):

su -c 'while [[ -d /proc/2296 ]]; do sleep 1; done; poweroff'


  • You can decide whether or not to shutdown after setting off the shell command
  • The shutdown is issued as root, the command to wait for is not necessarily done as root (no need to workaround the late sudo-password prompt).
share|improve this answer
Main point: This works even if the process has started. –  Heisenberg Dec 6 '14 at 8:15

You can use the && and || operators to chain commands together. For example:

apt-get update && sleep 2 && init 0

which will perform an update to the system using aptitude, wait 2 seconds, and go to runlevel 0, depending on your system this may or may not actually power off the hardware.

To speak to one or more operations following a more arbitrary operation, such as a, presumably web browser, download you would require additional logic to watch the downloading file to verify that the download has in fact completed, however, the shell logic is unchanged.

share|improve this answer

If you want to monitor an already started process, you can do this in a :

# while pgrep &>/dev/null -f process_name; do sleep 60; done; shutdown -h now
share|improve this answer

There is a application, named sentinella which can do it for you with its GUI: sentinella

for installing it:

sudo aptitude update
sudo aptitude install sentinella
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.