#Function to toggle wireless interfaces originaly created by Paul Sladen for Ubuntu acpi-support package for DEVICE in /sys/class/net/* ; do if [ -d $DEVICE/wireless ] ; then # $DEVICE is a wireless device. FOUND= # Yes, that's right... the new interface reverses the truth values. ON=1 OFF=0 for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do if [ -w "$CONTROL" ]; then FOUND=1 if [ "$(cat "$CONTROL")" = "$ON" ] ; then # It's powered on. Switch it off. echo -n "$OFF" > "$CONTROL" else # It's powered off. Switch it on. echo -n "$ON" > "$CONTROL" fi fi done # it might be safe to assume that a device only supports one # interface at a time; but just in case, we short-circuit # here to avoid toggling the power twice if [ -n "$FOUND" ]; then continue fi ON=0 OFF=1 # 1 for rf_kill, 2 for power/state for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do if [ -w $CONTROL ] ; then # We have a way of controlling the device, lets try if [ "`cat $CONTROL`" = 0 ] ; then # It's powered on. Switch it off. if echo -n $OFF > $CONTROL ; then break else OFF=2 # for power/state, second time around fi else # It's powered off. Switch it on. if echo -n $ON > $CONTROL ; then break fi fi fi done fi done