Re: Prevent hibernate/standby/sleep
Hi All,
Its already more than a year I posted my script for suspend in windows in this thread. Its nice to see that some new tools were developed
Anyway I have started to use Linux again as my primary OS. So here is script for Linux ->
For this script to work you need to install few more programs : xprintidle (prints user's idle time program), zenity (GUI for Shell Scripts), festival (text to speech program)
Than schedule it under root using cron (keep in mind that cron does not have full user environment so therefore the variables in crontab) every 5 minutes :
I think the script is selfexplanatory but : It simply check if there is connection established to ports 8895 or 23424. If there is no connection than popup window appears where time is running (3 min). Every minute computer voice will announce that computer is going to sleep in x minutes. If anything happens (for example you start streaming dlna, or just mouse movement) in this time then sleep is interrupted if nothing changes computer is put to sleep mode.
BTW : You have to disable the suspend in your system (dconf-editor, etc.), keep only monitor sleep time.
Feel free to modify the script and share your comments. For example if someone has time for that there could be maybe some additional check using some web camera face recognition software added to not suspend if there is someone sitting in front of computer, etc.
Its already more than a year I posted my script for suspend in windows in this thread. Its nice to see that some new tools were developed
Anyway I have started to use Linux again as my primary OS. So here is script for Linux ->
- Code:
#!/bin/bash
idle=`su -c "xprintidle" user`
echo `date`
echo "actual idle time in ms is $idle"
if [ "$idle" -gt "450000" ] ; then
if [ -n "`netstat -a -n | grep -e :8895 -e :23424 | grep ESTABLISHED`" ] ; then
echo "Connection established -> prevent sleep"
else
echo "No connection established to the server and idle time reached -> sleep in 180s"
echo "Computer is going to sleep in 3 minutes" | festival --tts &
# Progress window
COUNT="180"
START="180" # Set a start point.
until [ "$COUNT" -eq "0" ]; do # Countdown loop.
((COUNT-=1)) # Decrement seconds.
PERCENT=$((100-100*COUNT/START)) # Calc percentage.
echo "#Time remaining$(echo "obase=60;$COUNT" | bc)" # Convert to H:M:S.
echo $PERCENT # Outut for progbar.
case "$COUNT" in
"120" )
echo "Computer is going to sleep in 2 minutes" | festival --tts &
;;
"60" )
echo "Computer is going to sleep in 1 minute" | festival --tts &
;;
esac
sleep 1
done | zenity --title "Going to sleep .." --progress --percentage=0 --text="" --auto-close # Progbar/time left.
if [ $? = 1 ]; then exit $?; fi
# Progress window
idle=`su -c "xprintidle" user`
if [ -z "`netstat -a -n | grep -e :8895 -e :23424 | grep ESTABLISHED`" ] && [ "$idle" -gt "450000" ] ; then
echo "Nothing changed in 60s -> sleep now"
pm-suspend
else
echo "Sleep cancelled"
fi
fi
else
echo "idle time threshold not reached, maybe next time"
fi
For this script to work you need to install few more programs : xprintidle (prints user's idle time program), zenity (GUI for Shell Scripts), festival (text to speech program)
Than schedule it under root using cron (keep in mind that cron does not have full user environment so therefore the variables in crontab) every 5 minutes :
I think the script is selfexplanatory but : It simply check if there is connection established to ports 8895 or 23424. If there is no connection than popup window appears where time is running (3 min). Every minute computer voice will announce that computer is going to sleep in x minutes. If anything happens (for example you start streaming dlna, or just mouse movement) in this time then sleep is interrupted if nothing changes computer is put to sleep mode.
BTW : You have to disable the suspend in your system (dconf-editor, etc.), keep only monitor sleep time.
Feel free to modify the script and share your comments. For example if someone has time for that there could be maybe some additional check using some web camera face recognition software added to not suspend if there is someone sitting in front of computer, etc.