0

I'm trying to write a bash script so that Linux resets pulseaudio whenever I plug in or remove my USB DAC. So far it looks like this.

#/bin/bash
while :
do
    sleep 5
    if lsusb | grep YOURID
        then
            continue
    fi
    WHAT YOU WANT TO HAPPEN
done

When lsusb detects the device, it executes the command every 5 seconds I'd like to write two scripts, one that runs a command when plugged in, and one that runs a command when it's unplugged. I want the command to run only once instead of every 5 seconds and to work more than once, but I have no idea how to achieve this as my Bash skills are very limited. Any help?

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148

0 Answers0