Skip to content

Instantly share code, notes, and snippets.

@Akii
Created December 25, 2014 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akii/184afee617b467987bb9 to your computer and use it in GitHub Desktop.
Save Akii/184afee617b467987bb9 to your computer and use it in GitHub Desktop.
Hibernates the computer after sleeping for a while (don't use this without an SSD for obvious reasons)
#!/bin/bash
# /usr/lib/systemd/system-sleep/auto-hibernate.sh
# Go to hibernate in 30 minutes
autohibernate=1800
if [ "$1" = "pre" ] && [ "$2" = "suspend" ]
then
# Suspending, set RTC wake alarm
rtcwake -m no -s $autohibernate
fi
if [ "$1" = "post" ] && [ "$2" = "suspend" ]
then
# Coming out of sleep
lidState=$(awk '{print $2}' /proc/acpi/button/lid/LID/state)
# Wake up no longer required
rtcwake -m disable
if [ "$lidState" = "closed" ]
then
/usr/bin/systemctl hibernate
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment