Skip to content

Instantly share code, notes, and snippets.

@cmtsij
Created April 1, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmtsij/93fe5387d793088ab0d27fabe4bc446d to your computer and use it in GitHub Desktop.
Save cmtsij/93fe5387d793088ab0d27fabe4bc446d to your computer and use it in GitHub Desktop.
#!/bin/sh
filename=${0##*/}
usage()
{
cat<<EOF
Usage:
$filename <iface>
EOF
}
_iface_restart()
{
local iface="$1"
local module="$2"
echo "inerface: $iface"
echo "module: $module"
echo "==== reload start ===="
sudo -s <<EOF
echo "interface down: $iface"
ifconfig $iface down
echo "module remove: $module"
modprobe --remove $module
sleep 1
echo "module probe: $module"
modprobe $module
sleep 1
echo "interface up: $iface"
ifconfig $iface up
echo "==== reload done ===="
EOF
}
main()
{
iface="${1}"
if [ -z "$iface" ]; then
usage
exit 1
fi
module="$(basename $(readlink -f /sys/class/net/$iface/device/driver 2>/dev/null) 2>/dev/null)"
if [ -z "$module" ]; then
echo "Error: no module found" 1>&2
exit 1
fi
_iface_restart "$iface" "$module"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment