Skip to content

Instantly share code, notes, and snippets.

Created March 18, 2015 15:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/9c9d45c4818e3086ceca to your computer and use it in GitHub Desktop.
Save anonymous/9c9d45c4818e3086ceca to your computer and use it in GitHub Desktop.
/usr/local/sbin/remove_ignore_usb-device.sh
#!/bin/bash
# shellcheck.net: 4 warnings
logger -p info "$0 executed."
if [ "$#" -eq 2 ];then
removevendorid=$1
removeproductid=$2
usbpath="/sys/bus/usb/devices/"
devicerootdirs=`ls -1 $usbpath`
for devicedir in $devicerootdirs; do
if [ -f "$usbpath$devicedir/product" ]; then
product=`cat "$usbpath$devicedir/product"`
productid=`cat "$usbpath$devicedir/idProduct"`
vendorid=`cat "$usbpath$devicedir/idVendor"`
if [ "$removevendorid" == "$vendorid" ] && [ "$removeproductid" == "$productid" ]; then
if [ -f "$usbpath$devicedir/remove" ]; then
logger -p info "$0 removing $product ($vendorid:$productid)"
echo 1 > "$usbpath$devicedir/remove"
exit 0
else
logger -p info "$0 already removed $product ($vendorid:$productid)"
exit 0
fi
fi
fi
done
else
logger -p err "$0 needs 2 args vendorid and productid"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment