Skip to content

Instantly share code, notes, and snippets.

@dchakro
Last active March 31, 2021 19:44
Show Gist options
  • Save dchakro/571fe4d78219a9b4ff17690481c3afab to your computer and use it in GitHub Desktop.
Save dchakro/571fe4d78219a9b4ff17690481c3afab to your computer and use it in GitHub Desktop.
Automatic system sleep and wake Debian linux dietpi
#!/usr/bin/env bash
sudo -s
curl -ssL 'https://gist.github.com/dchakro/571fe4d78219a9b4ff17690481c3afab/raw/until_tomorrow.sh' >| /usr/local/bin/until_tomorrow
chmod +x /usr/local/bin/until_tomorrow
echo '30 22 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" until_tomorrow' >| /etc/cron.d/until_tomorrow
sudo -k
exit

What is this about?

These gist contains shell scripts to automate system sleep and wake on your machine running Debian linux (in my case DietPi).

until_tomorrow.sh is a bash script using rtcwake from the util-linux package to make your (supported) system sleep "now" and wake-up at a specified time.

How to use

Run the following line:

curl -ssL 'https://gist.github.com/dchakro/571fe4d78219a9b4ff17690481c3afab/raw/add_cronjob.sh' | bash

Tips

As a bonus run the script add_cronjob.sh to schedule your system suspend at a specific time.

Remember that the -m parameter in rtcwake can be tuned to your liking. e.g. you cou use -m disk to suspend to disk for most power efficiency or use -m standby for most responsiveness.

More info can be found on this blog (not a sponsor).

#!/usr/bin/env bash
day=$(date +%A)
if [[ "$day" == "Friday" || "$day" == "Saturday" ]]; then
# wakes up at 7 AM on weekends
wake_parameter=$(date +%s -d 'tomorrow 07:00')
else
# wakes up at 17.00 on weekdays
wake_parameter=$(date +%s -d 'tomorrow 17:00')
fi
# Evaluate with this line the effects of the command you're about to run.
# Check the tie etc.
# sudo rtcwake -m mem -l -t ${wake_parameter} --dry-run
# Real command that tells the system to suspend activity "now" and wake up at the specified time.
sudo rtcwake -m mem -l -t ${wake_parameter}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment