Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. while [ 1=1 ]; do # repeat forever
  4.  
  5. clear
  6.  
  7. echo "Updated: $(date '+%F %T')"
  8.  
  9. echo "### TIME SECTION"
  10.  
  11. SLEEP_H=18 # What hour should the system suspend at?
  12. WAKE_H=8 # What hour should the system wake up at?
  13.  
  14. # check what day of the week it is now
  15. DOW=$(date +%w) # 1 = monday, 5 = friday etc.
  16.  
  17. echo "Day of week: $DOW"
  18.  
  19. # check what time is it now
  20. H=$(date +%H)
  21. M=$(date +%M)
  22.  
  23. NOW_S=$(date +%s)
  24.  
  25. echo "Hour: $H, minute: $M"
  26.  
  27. #date +%s --date "tomorrow 8:00"
  28.  
  29. if [[ $DOW -lt 5 ]]; then
  30. echo "It's Monday to Thursday!"
  31. WAKE="tomorrow $WAKE_H:00"
  32. else
  33. echo "It's Friday to Sunday!"
  34. WAKE="monday $WAKE_H:00"
  35. fi
  36.  
  37. WAKE_S="$(date --date "$WAKE" +%s)"
  38.  
  39. WAKE_SR=$(( $WAKE_S - $NOW_S))
  40.  
  41. echo
  42. echo "Wake: $WAKE"
  43. echo "Wake relative seconds: $WAKE_SR"
  44. echo
  45. rtcwake -m no -s "$WAKE_SR"
  46.  
  47. # sleep section
  48.  
  49. sleep 15m
  50.  
  51. echo "### SLEEP SECTION"
  52.  
  53. if [[ $H -gt $SLEEP_H ]]; then # sleep if the hour is right
  54. systemctl suspend
  55. continue
  56. else
  57. echo "It's too early to sleep"
  58. fi
  59.  
  60. if [[ $DOW -gt 5 ]]; then # sleep if it's saturday or sunday
  61. systemctl suspend
  62. continue
  63. else
  64. echo "It's not weekend - gotta stay up!"
  65. fi
  66.  
  67. done
  68.  
  69. sudo crontab -e
  70.  
  71. @reboot exec /root/power-schedule.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement