Krisbee wrote: 
> Ah, bash one liners.  Why not just pgrep squeezeboxserver etc, or pidof?
> But in my case the server is remote and the ip is not known.  So I
> could just start squeezelite in debug mode with a log and check for
> "connected" in the log after a sleep.

Squeezelite does server discovery for you. 
Servers broadcast on udp port 3483 to signal their presence, you could
make a script to detect them.
Here is an old bit of perl script I dug out. It was used to specifically
find if a server was local and had CLI enabled, but I guess it would
work using the broadcast address instead of localhost, and HTTP instead
of CLI…
Code:
--------------------
    
  #!/usr/bin/perl
  …
  my %sc = ( # Discovered SB server running on this host
          timeout => 5, # Time we wait for a co-located SC server to respond
          name => '',   # This data filled after discovery - FIXME breaks on 
multiple servers.
          ip => '',
          cliport => ''
         );
  …
  unless (findSC()) {
  logger("No SC server running on this host. Who called me ?");
  exit;
  }
  logger("An SB server CLI plugin is running on this host: 
$sc{name}\@$sc{ip}:$sc{cliport}");
  …
  # Find current SC server on the host
  sub findSC {
  use IO::Select;
  use IO::Socket;
  my $retval = 0; 
  # Send discovery packet
  #my $disco = pack 'a5xa4xa4x', 'eIPAD', 'NAME', 'JSON'; # For HTTP
  my $disco = pack 'a5xa4xa4x', 'eCLIA', 'NAME', 'CLIP';  # For CLI
  my @scs;
  my $socket = new IO::Socket::INET->new(PeerPort => '3483',
                                         Proto =>'udp',
                                         LocalAddress => 'localhost',
                                         PeerAddr => 'localhost'
                                        ) or die;
  logger("Discovering local SC servers for $sc{timeout} seconds");
  $socket->send($disco);
  # Wait for a reply
  my @ready = IO::Select->new($socket)->can_read($sc{timeout});
  if (@ready) {
  my $stuff = $socket->recv(my $data, 100);
  if ($stuff) {
  my ($port, $ipaddr) = sockaddr_in($stuff) ;
  $ipaddr = inet_ntoa($ipaddr); # die if not local ?
  $data =~s/\s//g;
  my ($server, $cliport) = $data =~ /ENAME(.*?)CLIP(.*?)$/;
  $server = (split(/\./,"$server"))[0]; # Only the host name. useless on 
localhost.
  if ($server && $cliport) {
        logger("Response from $ipaddr:$port => SB server $server with CLI on 
port $cliport");
        push(@scs, { hostname => $server, ip => $ipaddr, cli => $cliport });
  }
  }
  }
  $socket->close;
  # store SC server details
  my $loopback = gethostbyname('localhost');
  $loopback = inet_ntoa($loopback);
  foreach my $server (@scs) { # When there is more than 1 server on localhost 
this won't do too well.
  if ($server->{ip} eq $loopback) {
  $sc{name} = $server->{hostname};
  $sc{ip} = $server->{ip};
  $sc{cliport} = $server->{cli};
  $retval = 1;
  last;
  }
  }
  return $retval;
  }
--------------------


------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=97046

_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to