#!/bin/bash # statAircard320U.sh # written by bob fulton BRAEWORKS July 2013 # script to check status on a Telstra Bigpond Sierra Wireless Aircard 320U 4G USB dongle # # provided AS IS, no warranties, etc. are provided 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 "check its there" TST=$(usb-devices 2> /dev/null | grep "Product=AirCard 320U") # echo $TST # test if [ -z "$TST" ]; then echo "Sierra Wireless AirCard 320U not found" exit 1 fi # echo "check $NET_ETH is up" TST=$(ifconfig | awk ' { print $1 } ' | grep $NET_ETH) if [ -z "$TST" ]; then # echo "Bring up $NET_ETH" # test ifconfig $NET_ETH up TST=$(ifconfig | awk ' { print $1 } ' | grep $NET_ETH) if [ -z "$TST" ]; then echo "Failed to bring up $NET_ETH" exit 1 fi fi 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() function is_connected() { local R=$(usbTermCmd "AT!SCACT?$MPPID" "-v" | grep "SCACT:") # echo "$R response" # test C=$(echo "$R" | awk -F ',' '{ print $2 }') # echo "$C" # test if [ "$C" == "0" ]; then echo "Not connected" else echo "Connected" return 1 fi return 0 } # is_connected() # get status is_connected "$1" if [ "$?" -gt 0 ]; then # connected USB0_IP=$(ip addr show dev $NET_ETH | grep inet | grep -v inet6 | awk '{ print $2 }') # echo "$USB0_IP" # test if [ -z "$USB0_IP" ]; then echo "ERROR: No ip address assigned from dhcp" else USB0_D=$(route -n | grep $NET_ETH | grep UG | awk '{ print $2 }') # echo "$USB0_D" # test if [ -z "$USB0_D" ]; then echo "ERROR: Default gateway not set to up from dhcp" fi fi fi if [ "$1" == "-v" ]; then # verbose usbTermCmd "AT!GSTATUS?" "$1" fi echo "Finish $PROG $VERSION on $(date '+%Y/%m/%d %H:%M:%S')" echo "" exit 0 # done # EOF