Revisited this issue and eventually came up with a small bash script using top to capture a "running" (as opposed to sleeping) process:
Code:
#!/bin/bash
while : # infinite loop until condition satisfied
do
if top -bcn 1 | grep "mplayer" | grep "R"; then
# "Do Something"
break
fi
done
Needs more work to do what I want but just showing the basics for now
EDIT
Final script in place:
Code:
#!/bin/bash
if top -d 1 -bcn 180 | grep "mplayer" | grep "R"; then
echo "Running"
else
echo passwd | sudo -S shutdown -r now
fi
and a crontab job:
Code:
*/10 * * * * /home/dpf/running.sh
The "180" means that top will look every second for 3 minutes. If it can grep an "R" in that time (images currently on screen for @ 2.5 mins) then all is OK, if it can't then it restarts the PC (lazy I know, will work on better solution, but it reboots so quickly, it makes not much difference). The crontab runs every 10 minutes. Only problem I have spotted is that sometimes mplayer doesn't move from S to R when it changes pictures (or this hapens so fast I don't see it or top doesn't capture it. top allows fractions of seconds so adjusting the runtime might sort this out. Would be easier if I could figure out a way to capture CPU % from top instead of S & R.....
[EDIT]
Neater solution without having to reboot:
Code:
#!/bin/bash
if top -d 1 -bcn 180 | grep "mplayer" | grep "R"; then
echo "Running"
else
screen -X quit #(stops gnu-screen)
echo passwd | sudo -S openvt -f -c 1 ./myscript.sh #(restarts script on actual physical display)
fi
http://ubuntuforums.org/showthread.p...6#post12644806
Bookmarks