Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Feb 2006
    Location
    Mid-Wales, UK
    Posts
    83

    How to tell, from a script, if server is streaming to a client?

    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.

    Thanks,

    Jon.

  2. #2
    Senior Member flattermann's Avatar
    Join Date
    Oct 2009
    Location
    Dortmund, Germany
    Posts
    774
    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.

    playerstatus.sh
    Code:
    #!/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"
    
    interact
    activeplayer.sh
    Code:
    #!/bin/sh
    ./playerstatus.sh | grep "mode%3Aplay" > /dev/null 2>&1
    if [ "$?" = "0" ]; then
    	echo "At least one player is streaming right now!"
    else
    	echo "No player is streaming!"
    fi
    Of course, you could improve the script by fetching the player ids from the server, but that's homework for you. ;-)
    Christian

    Home of SqueezeCommander - The SqueezeBox Remote Control App for Android

  3. #3
    Member
    Join Date
    Feb 2006
    Location
    Mid-Wales, UK
    Posts
    83
    Excellent, many thanks. I'll give those a go.

  4. #4
    Senior Member gharris999's Avatar
    Join Date
    Apr 2005
    Location
    Santa Fe, NM
    Posts
    3,299
    You might want to check out netcat (nc) which is a much lighter weight way than telnet to communicate via the CLI.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •