I'll just tack an extra echo on after the sleep command and grep for it
in the tripwire script.  When the sleep timer expires the script doesn't
need to kill the sleep process since it's already exited on it's own. 
On a newsong event the script does need to kill the sleep process so the
pipe to nc will be closed and nc will exit.  Just trying to clean up all
the processes before the main loop sets the tripwire back up again.

I think there might be a slim chance that the pgrep for the sleep pid
could return a pid for sleep spawned by some other process, which is why
I'm being specific with "sleep xx" and the -s 0 (even though I'm not
really sure what a session is exactly) rather than just a killall
sleep.

Originally I thought the pids for the pipelined processes were
consecutive which made it easy to start with the tripwire's pid and work
back to the sleep pid, and they often are consecutive but not always.


Code:
--------------------
    
  (echo -e "b8:27:eb:94:ae:63 subscribe playlist"; sleep 1h; echo "exit") | nc 
192.168.1.201 9090 | ./sod-npd-tripwire.sh
  
--------------------


A song with "exit" in the title would cause the tripwire to reset too
but I don't think that really matters as it shouldn't happen very
often.


Code:
--------------------
    
  #!/bin/sh
  
  while :
  do
  read line
  if echo $line | grep -e "newsong\|exit"
  then
  break
  fi
  done
  
  if pid=$(pgrep -s 0 sleep $scrsav)
  then
  kill $pid
  fi
  
--------------------


The $scrsav is just the sleep time set in the config file.  I'm thinking
about using that as a screen saver sort of thing - if you pause playback
there won't be any newsong events to break the tripwire so you'll have
wait for the sleep timer to expire.  Once it expires the main script can
check for playback mode and if it's paused clear the screen and replace
it with the screen saver image.


------------------------------------------------------------------------
sodface's Profile: http://forums.slimdevices.com/member.php?userid=19057
View this thread: http://forums.slimdevices.com/showthread.php?t=109694

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

Reply via email to