Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- while [ 1=1 ]; do # repeat forever
- clear
- echo "Updated: $(date '+%F %T')"
- echo "### TIME SECTION"
- SLEEP_H=18 # What hour should the system suspend at?
- WAKE_H=8 # What hour should the system wake up at?
- # check what day of the week it is now
- DOW=$(date +%w) # 1 = monday, 5 = friday etc.
- echo "Day of week: $DOW"
- # check what time is it now
- H=$(date +%H)
- M=$(date +%M)
- NOW_S=$(date +%s)
- echo "Hour: $H, minute: $M"
- #date +%s --date "tomorrow 8:00"
- if [[ $DOW -lt 5 ]]; then
- echo "It's Monday to Thursday!"
- WAKE="tomorrow $WAKE_H:00"
- else
- echo "It's Friday to Sunday!"
- WAKE="monday $WAKE_H:00"
- fi
- WAKE_S="$(date --date "$WAKE" +%s)"
- WAKE_SR=$(( $WAKE_S - $NOW_S))
- echo
- echo "Wake: $WAKE"
- echo "Wake relative seconds: $WAKE_SR"
- echo
- rtcwake -m no -s "$WAKE_SR"
- # sleep section
- sleep 15m
- echo "### SLEEP SECTION"
- if [[ $H -gt $SLEEP_H ]]; then # sleep if the hour is right
- systemctl suspend
- continue
- else
- echo "It's too early to sleep"
- fi
- if [[ $DOW -gt 5 ]]; then # sleep if it's saturday or sunday
- systemctl suspend
- continue
- else
- echo "It's not weekend - gotta stay up!"
- fi
- done
- sudo crontab -e
- @reboot exec /root/power-schedule.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement