Hey DJanGo,

Thank you for your script. I 've adapted it a little for my purpose. a
crontab runs the script every 15 minutes. is the script called 10 times
and the player will still on status "play" then i restart this player.
'issue 2 from this post'
(http://forums.slimdevices.com/showthread.php?97046-Announce-Squeezelite-a-small-headless-squeezeplay-emulator-for-linux-(alsa-only)&p=789016&viewfull=1#post789016)

the player starts up every 2.5 hrs new but I can live with this small
gaps.


Code:
--------------------
    #!/bin/bash
  ## check if any player is playing
  ## and restart squeezelite if timetoplay is equal on both checks
  
  ##vars
  port=9090
  server=localhost
  
  # use a fresh logfile
  mv /tmp/playercheck.log /tmp/playercheck.txt
  echo "$(date)">/tmp/playercheck.log
  #sensors|grep 'Core 0' |awk '{print $3}'|cut -b2,3,4,5,7>>/tmp/playercheck.log
  
  # get number of known players
  players=$(printf "player count ?\nexit\n" | nc $server $port | cut -d ' ' -f 
3)
  
  ## check all known players
  for((i=0; i<$players; i++))
  do
  playerID=$(printf "player id $i ?\nexit\n" | nc $server $port | cut -d ' ' -f 
4 | sed 's/%/%%/g')
  playermodel=$(printf "player model $i ? \nexit\n" | nc 127.0.0.1 9090 |cut -d 
' ' -f 3)
  
  if [ !$playermodel = squeezelite ]
  then
  echo Player Nr. $i is not a squeezelite Session>>/tmp/playercheck.log
  else
  playername=$(printf "$playerID name ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  playermode=$(printf "$playerID mode ? \nexit\n" | nc 127.0.0.1 9090 |cut -d ' 
' -f 3)
  if [ $playermode != play ]
  then
  echo 0 > /tmp/$playername.txt
  fi
  if [ $playermode = pause ]
  then
  grep $playername:$playermode /tmp/playercheck.txt && printf "$playerID power 
0 \nexit\n" | nc $server $port
  echo $playername:$playermode>>/tmp/playercheck.log
  else
  timetoplay1=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  echo "$playername:Playtime:$timetoplay1">>/tmp/playercheck.log
  timetoplay2=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  if [ $timetoplay1 = $timetoplay2 ]
  then
  echo no difference between 1st and 2.nd check
  timetoplay3=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  if [ $timetoplay1 = $timetoplay3 ]
  then
  printf "$playerID power 0 \nexit\n" | nc $server $port
  fi
  else
  echo "$playername is playing nothing 2do 4me">>/tmp/playercheck.log
  call_duration=$(cat /tmp/$playername.txt | head -n1  | tail -n1)
  if [ $call_duration -lt 10 ]
  then 
  echo $(echo "$call_duration + 1" | bc) > /tmp/$playername.txt 
  else
  printf "$playerID power 0 \nexit\n" | nc $server $port
  printf "$playerID play \nexit\n" | nc $server $port
  echo 0 > /tmp/$playername.txt
  fi
  fi
  fi
  fi
  done
--------------------


THX


------------------------------------------------------------------------
sevi_at's Profile: http://forums.slimdevices.com/member.php?userid=63076
View this thread: http://forums.slimdevices.com/showthread.php?t=99916

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

Reply via email to