#!/usr/bin/env python # -*- coding: utf-8 -*- # Simple shutdown timer-script for gnome to actually shut the computer down sometimes ;p # by Sven (admin@ganz-sicher.net) # Last Update: 11.03.2011 # # Dependencies: gnome, notify-send (libnotify-bin), sudo # Installation: move script to /usr/bin/ and make sure it's executable # # Usages: sudo python justInTimer # sudo python justInTimer def main(): # Modules import time import subprocess import sys # Functions # differend actions depending on left time (status messages and shutdown) def inf(i): # Gnome Status messages (10min, 5min & 1min left) if i+11 == mytime: subprocess.Popen("notify-send -i /usr/share/icons/gnome/48x48/status/dialog-warning.png 'NOTICE: PC will be shut down in 10 minutes...'", shell=True) elif i+6 == mytime: subprocess.Popen("notify-send -i /usr/share/icons/gnome/48x48/status/dialog-warning.png 'NOTICE: PC will be shut down in 5 minutes.'", shell=True) elif i+2 == mytime: subprocess.Popen("notify-send -i /usr/share/icons/gnome/48x48/status/user-idle.png 'Warning: Shutting down in 1 minute!'", shell=True) # Shutdown when time is over elif i+1 == mytime: subprocess.Popen("shutdown -h now", shell=True) # script called with (valid) argument? try: mytime = int(sys.argv[1]) except: # Ask User for duration mytime = raw_input("Please enter the minutes you want to have until shutdown: ") try: mytime = int(mytime) except: print "Unzulaessige Eingabe, bitte Zahl eingeben!" exit(1) print 'Okay, shutting down in ',mytime ,' minutes.' raw_input('Please confirm this duration with ENTER... ') subprocess.Popen(["python","/usr/bin/justInTimer",str(mytime)], shell=False) exit(0) # count the time and check for actions every minute (inf()-function) for i in xrange(mytime): time.sleep(60) inf(i) return 0 if __name__ == '__main__': main()