Advertisement
depwl9992

PreventSpindown.py

Apr 24th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. # This script runs once a minute via crontab. /media/NETWRK is a router-attached network drive mounted at startup.
  4. # Since the 5yo 2TB WD tends to spin down every 90 seconds or so, this simply pings it once a minute to keep it active.
  5. # Settings allow sleep periods during certain hours of the day and days of the week where the drive will probably not be in use.
  6.  
  7. import datetime as dt
  8. import sys
  9.  
  10. Enabled=1
  11. WeekDays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
  12. SleepStart = 23
  13. SleepEnd = 6
  14. SleepDays = ["Saturday","Sunday"]
  15. Filename = "/media/NETWRK/tmp.txt"
  16.  
  17. if not Enabled:
  18.         # print("Terminated by enable")
  19.         sys.exit()
  20.  
  21. Hour = dt.datetime.today().hour
  22. DOW = dt.datetime.today().weekday()
  23.  
  24. # print(str(Hour) + ", " + str(DOW))
  25.  
  26. if SleepStart > SleepEnd:
  27.         if Hour > SleepStart or Hour < SleepEnd:
  28.                 # print("Terminated by Sleep")
  29.                 sys.exit()
  30. else:
  31.         if Hour > SleepStart and Hour < SleepEnd:
  32.                 # print("Terminated by Sleep")
  33.                 sys.exit()
  34.  
  35. for w in SleepDays:
  36.         if WeekDays[DOW] == w:
  37.                 # print("Terminated by DOW")
  38.                 sys.exit()
  39.  
  40. # print("Got here!")
  41. f = open(Filename,"w")
  42. f.write("Temporary String " + str(dt.datetime.now()))
  43. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement