Wednesday, August 27, 2014

Checking if rdairplay is running

I was having a few problems with rdairplay crashing randomly and leaving silence on air. I made a script to check if it is running and restart if neccessary and delete the rdairplaylock file. I hope someone finds this usefull.
 I think someone wrote something similar a while back using a while loop or something.
You could run it periodically using crontab if you wished?
When you save this file dont include the word "rdairplay" as part of the file name or else the running of this script will show up as an "rdairplay" process on your system. I called my script ... but you can choose a name that suits you.


# This returns a value of 0 (if not running) or 1 (if rdairplay running)

statusrdairplay=`ps x | grep -v grep | grep -c rdairplay`

echo $statusrdairplay

 if [ $statusrdairplay = "1" ]; then
 echo "rdairplay is running"

# Remove rdlockfile Change the path to the rdairplaylock file on your set up.
rm /home/geoff2/.rdairplaylock

# Start rdairplay /usr/bin/rdairplay &

#Pause for 10 seconds to give rdairplay time to start up prior the running rmlsend command sleep 10

#Optional you could add this rmlsend line here to play next track if you wished
rmlsend PN\ 1\!



1 comment:

sebleblanc said...

Nitpicking, but you should use `pgrep ` instead of `ps | grep -v grep | grep ` idiom. `pgrep` matches directly on the actual process name, not on the output of `ps`.

Cool script!