#!/bin/sh WIRELESS="$1" # First try a minor cycle ESSID=$(/sbin/iwconfig "$WIRELESS" 2>/dev/null |grep ESSID |perl -ne 'm/\"([^\"]+)\"/ && print $1,qq(\n)') if [ -n "$ESSID" ]; then sudo iwconfig "$WIRELESS" essid "$ESSID" sleep 1s; if /sbin/iwconfig "$WIRELESS" 2>/dev/null | grep 'Bit Rate'|grep -qv '=1 Mb/s'; then exit 0 fi; fi; # Failure, so major cycle sudo ifdown wireless; if [ "$WIRELESS" == "wireless" ]; then if lsmod|grep -q bcm43xx; then sudo modprobe -r bcm43xx; sudo modprobe bcm43xx; else sudo modprobe -r b43; sudo modprobe b43; fi; sleep 2s; fi; sudo ifup "wireless";