Skip to content

Instantly share code, notes, and snippets.

@dchakro
Last active October 28, 2025 16:48
Show Gist options
  • Select an option

  • Save dchakro/571fe4d78219a9b4ff17690481c3afab to your computer and use it in GitHub Desktop.

Select an option

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
echo "45 23 * * * root sudo /usr/sbin/rtcwake -m mem -t $(date +\%s -d 'tomorrow 0700')" >| /etc/cron.d/until_tomorrow
sudo -k
exit
# echo "40 22 * * 1-5 root sudo /usr/sbin/rtcwake -m mem -t $(date +\%s -d 'tomorrow 0700')" >| /etc/cron.d/until_tomorrow

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