I have a bash script that basically starts an audio stream using mplayer:
#!/bin/bash
# startmusic.sh
/usr/bin/mplayer http://www.audiostream.com
what I want to make sure is that if mplayer chrashes or ends of any reason, it gets automatically restarted. I therefore have a cron job running every minute which also is a bash script:
#!/bin/bash
# interval.sh
if [ -z "$(pgrep mplayer)" ]; then
#restart music
(
exec </dev/null
exec >/dev/null
exec 2>/dev/null
umask 0
cd /
bash /home/user/startmusic.sh
) &
else
echo "music already playing, no need to restart startmusic.sh"
fi
One odd thing that makes this script not very useful is that it seems that mplayer is starting 2 instances, and if the player stops (as it e.g. does when the connection is lost), only 1 mplayer instance quits, still leaving one left. Since my programming skills are quite rudimentary, I would greatly appreciate any (easy-to-implement) solutions. Thanks in advance/J