#!/bin/bash # openAircard320U.sh # written by bob fulton BRAEWORKS Nov 2012 # script to disconnect a Telstra Bigpond Sierra Wireless Aircard 320U USB dongle # have not needed to use this script as part of the system events # provided AS IS, no warranties, etc. are provided # after a few requests added the read back from the modem VERSION=V1.11 PROG="$(basename $0)" BASEDIR="/custom/broadband" . ${BASEDIR}/commonAircard320U.inc echo "Start $PROG $VERSION on $(date '+%Y/%m/%d %H:%M:%S')" if [ ! -z "$USER" -a "$USER" != "root" ]; then echo "Must be root (not $USER) user to execute $PROG." exit 1 fi # echo "kill dhclient for $NET_ETH" # test TST=$(ps ax | grep 'dhclient' | grep $NET_ETH | grep -v 'grep') if [ ! -z "$TST" ]; then echo "Stop dhclient on $NET_ETH" PID=$(echo "$TST" | awk '{ print $1 }') kill -s HUP "$PID" echo "Clean up the dhclient mess" sleep 5 rm -f "/etc/resolv.conf" cp -f "${BASEDIR}/resolv.conf-standard" "/etc/resolv.conf" "/etc/init.d/named" restart # restart dns server fi # NOTE: the "resolv.conf-standard" contains a clean version of "/etc/resolv.conf". # the dhclient does not revert the "/etc/resolv.conf" cleanly with a signal lost or lease renew fail # E.G. of a my clean "/etc/resolv.conf" saved in "resolv.conf-standard" # snip start #-- ; resolv.conf-standard - used to replace the stuffed /etc/reslov.conf that dhclient leaves behind #-- search braeworks.local #-- nameserver 192.168.0.9 # snip end # (remove the leading single #-- ) USBTERM_RESPONSE="" # sometimes the doggle provides erronenous responses (typically trying to use part of a previous command) function usbTermCmd() { # $1=outCmd, [$2=-v (verbose)] USBTERM_RESPONSE="" echo -e "${1}\r" > "$MODEM_PORT" while read -t $READ_TOUT R do if [ "${#R}" -lt 1 ]; then continue; fi # forget blank lines USBTERM_RESPONSE="$R" # save the last line (usually OK or ERROR) if [ ! -z "$2" -a "$2" == "-v" ]; then echo "$R"; fi done < "$MODEM_PORT" return 0 } # usbTermCmd() # check its there TST=$(usb-devices 2> /dev/null | grep "Product=AirCard 320U") if [ -z "$TST" ]; then echo "Sierra Wireless AirCard 320U not found" else # echo "Disconnect" # test usbTermCmd "AT!SCACT=0,$MPPID" > /dev/null if [ "$USBTERM_RESPONSE" == "OK" ]; then echo "Disconnected" fi fi echo "Reload network defaults" # test /etc/init.d/network restart echo "Finished $PROG $VERSION on $(date '+%Y/%m/%d %H:%M:%S')" echo "" # EOF