Skip to content

Instantly share code, notes, and snippets.

@UdeRecife
Last active February 10, 2016 23:29
Show Gist options
  • Save UdeRecife/88a9822466c7feba6e5b to your computer and use it in GitHub Desktop.
Save UdeRecife/88a9822466c7feba6e5b to your computer and use it in GitHub Desktop.
Script to reset usb ports, covering all possible cases.
#!/bin/sh
if [ "$(id -u)" != 0 ] ; then
echo This must be run as root!
exit 1
fi
#
# Look for the most comment cases
#
for driver in xhci_hcd ehci_hcd uhci_hcd xhci-pci ehci-pci uhci-pci ; do
#
# The directory to operate within
#
dir=/sys/bus/pci/drivers/${driver}
#
# If it exists we have the appropriate USB-driver
#
if [ -d $dir ]; then
echo "Reseting: ${driver}"
cd ${dir}
for dev_id in ????:??:??.? ; do
if [ "${dev_id}" == "????:??:??.?" ] ; then
break
fi
printf "${dev_id}" > unbind
printf "${dev_id}" > bind
done
else
echo "Not present: ${driver}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment