Since you're thinking of looking at my script, here's a cleaned up
version.  It makes it a little more obvious where to put one's
commands.

I call it "watch_usb_audio".


Code:
--------------------
    #!/bin/sh
  
  exec >/home/tc/watch_usb_audio.log 2>&1
  
  audiodev=$1
  
  usage()
  {
  cat <<EOF >&2
  usage: $0 audio-device-name
  
  The only argument to this script should be your USB audio device
  name, as seen in /proc/asound.  On my machine my Harman Kardon
  Soundsticks show up as "Soundsticks":
  $ ls -F /proc/asound
  Headphones@  card1/       hwdep        pcm          version
  SoundSticks@ cards        modules      seq/
  card0/       devices      oss/         timers
  EOF
  exit 1
  }
  
  if [ ! "$audiodev" ]
  then
        usage
  fi
  
  
  log()
  {
        echo  $(date +%Y-%m/%d-%X) "$@"
  }
  
  device_present()
  {
  test -e /proc/asound/$audiodev
  }
  
  wait_for_device()
  {
        while ! device_present
        do
                sleep 4
        done
  }
  
  wait_for_device_to_go_away()
  {
        while device_present
        do
                sleep 4
        done
  }
  
  watch_usb_audio()
  {
        while : loop forever
        do
                wait_for_device
  
                log $audiodev is now present
  
                # commands to run when the device is plugged in go here
                alsactl restore
                /usr/local/etc/init.d/squeezelite restart
  
                wait_for_device_to_go_away
  
                log $audiodev has vanished
                # commands to run when the device is plugged in go here
  
        done
  }
  
  
  log "Watching for USB device '$audiodev'"
  if ! device_present
  then
        log Device not present at startup.  Will wait...
  fi
  
  watch_usb_audio &
  
--------------------


------------------------------------------------------------------------
pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510
View this thread: http://forums.slimdevices.com/showthread.php?t=113661

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

Reply via email to