Last active
August 29, 2015 14:06
-
-
Save igal1c0de4n/0e0e39815ec7a0fa9b25 to your computer and use it in GitHub Desktop.
Are you running Linux with Gnome-Shell, installed packages and auto-suspend is broken? You can use this bash script to force suspend when system is idle!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
log() | |
{ | |
echo "$(date): $@" >> /tmp/autosuspend.log | |
} | |
load_threshold() | |
{ | |
DOTCONFIG="$HOME/.autosuspend" | |
if [ ! -e "$DOTCONFIG" ] ; then | |
echo "auto-creating $DOTCONFIG" | |
echo 5 > "$DOTCONFIG" | |
fi | |
IDLE_THRESHOLD_MIN=`cat $DOTCONFIG` | |
THRESHOLD_MS=$((IDLE_THRESHOLD_MIN * 60 * 1000)) | |
log "suspend idle time threshold:\ | |
$THRESHOLD_MS ms ($IDLE_THRESHOLD_MIN min)" | |
} | |
init() | |
{ | |
IDLE_THRESHOLD_MIN=$1 | |
INTERVAL_SEC=$2 | |
[ -n "$INTERVAL_SEC" ] || INTERVAL_SEC=10 | |
load_threshold | |
} | |
suspend_when_idle() | |
{ | |
MAX_DIM_TIME_MS=$((1000 * 30)) | |
while true ; do | |
sleep $INTERVAL_SEC | |
IDLE_TIME_MS=$((`xprintidle`+ 80)) | |
if ((IDLE_TIME_MS > THRESHOLD_MS)) ; then | |
log "idle time: $IDLE_TIME_MS, suspending" | |
gnome-screensaver-command --lock | |
sudo pm-suspend | |
fi | |
done | |
} | |
monitor_threashold_change() | |
{ | |
while true ; do | |
inotifywait $DOTCONFIG | |
load_threshold | |
done | |
} | |
init | |
monitor_threashold_change & | |
suspend_when_idle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
apt-get install xprintidle pm-utils
$ sudo cat sudoers.d/power
%powerdev ALL=NOPASSWD: /usr/sbin/pm-suspend,
/usr/sbin/pm-suspend-hybrid,
/usr/sbin/pm-hibernate