Skip to content

Instantly share code, notes, and snippets.

Forked from RomkeVdMeulen/suspend_until
Last active August 29, 2015 14:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save almereyda/c40672b4c825787e3935 to your computer and use it in GitHub Desktop.
# Auto suspend and wake-up script
# Puts the computer to sleep and automatically wakes it up at specified time
# Written by Romke van der Meulen <>
# Takes a 24-hour time HH:MM as its argument
# Example:
# suspend_until 9:30
# suspend_until 18:45
# ------------------------------------------------------
# Argument check
if [ $# -lt 1 ]; then
echo "Usage: suspend_until HH:MM"
# Check whether specified time today or tomorrow
DESIRED=$((`date +%s -d "$1"`+7200))
NOW=$((`date +%s`))
if [ $DESIRED -lt $NOW ]; then
DESIRED=$((DESIRED + 24*60*60))
# Kill rtcwake if already running
sudo killall rtcwake
# Set RTC wakeup time
sudo rtcwake -t $DESIRED -m on &
# feedback
echo "Suspending..."
# give some time to cancel if needed
sleep 2
# then suspend
sudo pm-suspend
# Wake up with monitor off
xset dpms force off
# Kill rtcwake if still running
sudo killall rtcwake
# Any commands you want to launch after wakeup can be placed here
# Remember: sudo may have expired by now
echo "Good morning!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment