Skip to content

Instantly share code, notes, and snippets.

@Snawoot
Created September 4, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Snawoot/b754872ce914859ab835bb7b12d1e9e2 to your computer and use it in GitHub Desktop.
Save Snawoot/b754872ce914859ab835bb7b12d1e9e2 to your computer and use it in GitHub Desktop.
Shell script to restart USB wifi adapter on Linux
#!/bin/sh
for device in $(ls /sys/bus/usb/devices/*/product) ; do
dir="$(dirname "$device")"
if [ "$(cat "$device")" = "802.11n NIC" ] ; then
port="$(basename "$dir")"
echo Restarting "$port"...
echo "$port" > /sys/bus/usb/drivers/usb/unbind
sleep 2
echo "$port" > /sys/bus/usb/drivers/usb/bind
echo "Port $port restarted."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment