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