View Full Version : How to tell, from a script, if server is streaming to a client?

2010-03-11, 04:07
I want to be able to tell from a shell script if any of my clients are playing music from the server. Is there a relatively simple way to do this? I tried experimenting with lsof but drew a blank. Any suggestions appreciated.



2010-03-11, 06:09
Maybe there are easier solutions, but that's a small solution that I've written right now:

You need two scripts:
"playerstatus.sh" gets the status of your players from the server
"activeplayer.sh" tells you if any of the players is streaming right now

You need to install "expect" to make the scripts work.


#!/usr/bin/expect -f
# Get the player status of your local SBS

# Your server name/ip
set host media
# Server CLI port (9090)
set port 9090

# Set your playerIds here (separated by ";")
set players "00:04:20:XX:XX:XX;00:04:20:YY:YY:YY;00:04:20:ZZ:ZZ :ZZ"

# Credentials are only needed if enabled on server
set user username
set pass password

spawn telnet $host $port

send "login $user $pass\n"

foreach player [ split $players {";"} ] {
send "$player status\n"

sleep 1

send "exit\n"



./playerstatus.sh | grep "mode%3Aplay" > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo "At least one player is streaming right now!"
echo "No player is streaming!"

Of course, you could improve the script by fetching the player ids from the server, but that's homework for you. ;-)

2010-03-11, 07:43
Excellent, many thanks. I'll give those a go.

2010-03-11, 08:27
You might want to check out netcat (nc) which is a much lighter weight way than telnet to communicate via the CLI.