Reputation: 119
I use mpg123 to read an mp3 webradio stream (port 8000). Sometimes, the webradio server stops but mpg123 doesn't quit. Also, if the network on my machine fails, mpg123 won't quit either. I would like to monitor mpg123 activity using a bash script launched by cron. Something like this:
tcpdump -i eth0 port 8000 2>/dev/null | head | wc -l &
sleep 5
killall tcpdump
If no stream is played by mpg123, the result will be 1. Otherwise, it will be > 1.
How can I get this result into a variable? Then I could relaunch mpg123 if the streaming has failed.
Note that I can't use the timeout command and I can't write anything on my system.
Upvotes: 0
Views: 494
Reputation: 641
possibly
isitthere=$(tcpdump -i eth0 port 8000 2>/dev/null | head | wc -l & sleep 5; killall tcpdump)
if [[ $isitthere -eq 1 ]]
then
SET FIRE TO EVERYTHING
fi
not sure if it'd handle the sleep 5. But can't you use a -ll switch on tcp dump so..
worth a shot.
Upvotes: 1