1

I often run long calculations on my computer and I would like to shut it down when this are terminated.

Is there some option to shutdown the computer when a specific process termanates? Thanks for the help!

lucacerone
  • 1,690

2 Answers2

2

This should do the trick:

http://www.makeuseof.com/tag/cuttlefish-set-actions-reactions-automate-ubuntu/

Mrokii
  • 502
  • Thanks this seem would do the trick.. is it in the repos? – lucacerone Aug 11 '12 at 07:51
  • Not that I knew. According to the tutorial you have to add a ppa. Reply back if you need help with it. – Mrokii Aug 14 '12 at 20:48
  • 1
    Cuttlefish is now also in the extras repository of Ubuntu. So you should be able to install it through the Software Center without adding the PPA. – Alex Sep 20 '12 at 10:58
0

I don't know any out-of-the-box solution for this, but you could make cron check if the process is still there every hour or so. You could put something like this in a suitable place chmod it executable by root and symlink to it from /etc/cron.hourly :

#!/bin/bash
PROCESSNUM = `ps x | grep -c "calculationthingy"` 
if [ "$PROCESSNUM" -lt 1 ] 
then
    # Make sure this in inactivated! 
    rm symlink_in_etc_hourly
    shutdown -h now 
fi
Hinz
  • 562
  • thanks for the answer, but I can't entirely understand what the script does.. it gets the process number.. ok.. but what is that rm etc line? and which line I have to be sure it is inactive??? – lucacerone Aug 11 '12 at 07:49
  • It counts the number of running processes of what ever it is you are running. If this gets less than one it will shutdown the computer. But when you boot again, the script will still be run every hour (assuming you run it by linking to it in /etc/cron.hourly). If you don't have any processes of your calculating software running, the system will shutdown in your face the next time cron does its hourly job. To avoid that it might be a good idea to make the script inactivate itself by deleting the link to itself in cron.hourly. A bit crude, admittedly, but should do the job. – Hinz Aug 11 '12 at 20:42