Reputation: 1
I am trying to create a script to use a movie as ScreenSaver, but once the movie is opened, the system freezes and reboots.
I have been pulling hairs off of my head because I cannot figure out why this happens. I tried the same script in another machine and it worked perfectly for many months...
The machine it worked on was a Linux Mint 13 machine and the one it didn't work on was a Linux Mint 17 machine.
The script is the following:
#!/bin/bash
screen_on=false;
state=0;
time_idle=1200;
while true;do
IDLE=$(./idletime)
if [ $IDLE -gt $time_idle ];then
if [ $(pidof mplayer) ];then
echo "Screen is on " >> mylog.log
else
./test.sh &
fi
else
if [ $(pidof mplayer) ];then
pkill mplayer
else
echo "Screen is off." >> mylog.log
fi
fi
done
The idletime program is actually the same as xprintidle... It uses the X Server to get the system's idle time. The test.sh script is as follows:
#!/bin/bash
mplayer -nostop-xscreensaver movie.mp4 -fs -loop 0
Thank you!
Upvotes: 0
Views: 3028
Reputation: 123470
What's probably happening is a Denial of Service attack.
If you have two mplayer processes, your script starts bombing the system, starting an infinite number of mplayers as quickly as possible.
Use shellcheck. It would have warned you about missing quotes in if [ $(pidof mplayer) ]
. The correct code is:
if [ "$(pidof mplayer)" ]
then
echo "There is one or more mplayer processes"
else
echo "There are no mplayer processes."
fi
It can be more directly written as
if pidof mplayer > /dev/null
then
...
PS: You can also replace while true
with while sleep 1
, which will reduce the script's CPU usage from 100% to <1% with no loss of functionality.
Upvotes: 3