prevent sleep script

For help and support with issues specific to Linux/Unix
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply.

prevent sleep script

Postby bandolero » Fri Oct 19, 2012 1:47 am

Hello; I had not luck with the infamous "Prevent sleep if streaming" option on my 64 bit chakra linux desktop, so i wrote a linux script based on the idea I found on a Seven thread; it periodically pings PS3 IP, if the PS3 is alive then simulate a shift key pressed with the xdotool command (must be installed).

Code: Select all
#!/bin/sh

# Checks every $SLEEP seconds if PS3 is alive.
# If this happens, prevent sleep.


SLEEP=180
PS3IP=192.168.1.130

# Checks if script is already running
if pidof -x $(basename $0) > /dev/null; then
  for p in $(pidof -x $(basename $0)); do
    if [ $p -ne $$ ]; then
      echo "Script $0 is already running: exiting"
      exit
    fi
  done
fi

# Checks if PS3 Mediaserver is running
if [ -z 'ps -ef |grep ps3 |grep -v grep | awk '{print$2}'' ]; then
    echo "PMS not found. Dying" ; exit 1
fi

# Periodically pings PS3
while true; do
   echo "Checking"
   
   if [[ $(ping -q -c 3 ${PS3IP}) == @(*100% packet loss*) ]]; then
      echo "PS3 is down"
   else
       echo "PS3 is alive, preventing sleep"
       xdotool key shift
   fi
   sleep ${SLEEP}
done



Seconds to sleep is written in SLEEP at beginning, and the PS3 IP in PS3IP, you must change it with your settings.
I installed xdotool in Chakra linux with the ccr command, google it for Ubuntu or other distros.


I have PS3 Mediaserver installed as a service, I don't know if it works otherwise.
bandolero
 
Posts: 4
Joined: Tue Jan 03, 2012 2:03 am

Return to Linux/Unix Support

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests