FAQ  •  Register  •  Login

Prevent hibernate/standby/sleep

<<

J.M.

Serviio newbie

Posts: 4

Joined: Fri May 31, 2013 8:37 am

Post Thu Jul 24, 2014 2:50 pm

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 ->

  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 :

  Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
SHELL=/bin/bash
DISPLAY=:0
XAUTHORITY=/home/user/.Xauthority
*/5 * * * * /home/user/idle.sh 1>>/home/user/idle.txt 2>>/home/user/idle.txt


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.
<<

eNdEmiOn

Serviio newbie

Posts: 13

Joined: Mon Mar 16, 2015 1:07 pm

Post Thu Oct 20, 2022 2:08 pm

Re: Prevent hibernate/standby/sleep

2022 And serviio still has no sleep prevent option?
<<

SlimShaggy

Serviio newbie

Posts: 1

Joined: Sat Nov 05, 2022 10:21 pm

Post Sat Nov 05, 2022 10:24 pm

Re: Prevent hibernate/standby/sleep

eNdEmiOn wrote:2022 And serviio still has no sleep prevent option?

I also encountered this problem today. The common advice to disable sleep when plugged is not very useful because Windows often wakes up at night to install updates and then never goes back to sleep if sleep is disabled.
Previous

Return to Feature requests

Who is online

Users browsing this forum: No registered users and 22 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.