Created
November 9, 2013 11:39
-
-
Save TheRusskiy/7384586 to your computer and use it in GitHub Desktop.
Execute shell command after a specified time period. E.g. shutdown computer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
import time | |
execute_after_minutes = 17 | |
command = 'shutdown /h' | |
# 'shutdown /s' #shutdown | |
# 'shutdown /h' #hibernate | |
def now(): | |
return datetime.datetime.now() | |
def is_time(the_time): | |
return now()>the_time | |
shift = datetime.timedelta(minutes = execute_after_minutes) | |
shutdown_time = datetime.datetime.now()+shift | |
while True: | |
if is_time(shutdown_time): | |
os.system(command) | |
break | |
diff = shutdown_time - now() | |
hours = diff.seconds / 3600 | |
mins = (diff.seconds-hours*3600) / 60 | |
secs = (diff.seconds-hours*3600-mins*60) | |
print( 'Left: '+str(hours)+'h '+str(mins)+'m '+str(secs)+'s' ) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment