This is a better solution to the previous issue.
I've created 2 scripts the first is this...
sudo /home/{your user name}/UMM.sh
By launching this "In Terminal" if you create an icon, you can punch in you sudo password.
The UMM.sh it calls is as follows...
To make it work for you you will have to read and change the stuff at the top of the script. You may also have to change some of the sleep
lines to suit your situation.
Have Fun!
#!/bin/bash
# *****************************************************************
#Change the following values based on your connection type and name
#Running 'nmcli -t -f TYPE,STATE dev'
#cdma or gsm (edit below)
ConType="cdma"
#Running 'nmcli -t -f NAME,TYPE con'
#The name of your connection in the network manager (edit below)
ConName="Zantel connection"
#Running 'lsusb'
#Get the Vendor and Model ID for your modem (edit below)
USB_Vendor=12d1
USB_Product=1001
#Running 'ifconfig'
#Get the Internet Connection (edit below)
IntCon=ppp0
# ******************************************************************
Network_State=$(nmcli -t -f TYPE,STATE dev)
echo -e
echo -e "Current Network Status: \r"
echo $Network_State
i=0
error_count=0
#default 600
Good_connect_count=600
i=$[Good_connect_count - 50]
Default_ping_host="google.com"
pingtest=0
while true; do
#First off determine nature of problem if one exists
#Test to see if our connection type even exists
MT=C nmcli -t -f TYPE,STATE dev | grep -q $ConType
if [ $? -eq 0 ]; then
#Check to see if the WWAN is enabled
MT=C nmcli -t -f WWAN nm | grep -q "enabled"
if [ $? -eq 0 ]; then
#Check to see if we have a ppp0 connection
MT=C ifconfig | grep -q $IntCon
if [ $? -eq 0 ]; then
error_count=$error_count
else
dt=$(date)
echo At $dt we have no $IntCon connection...
echo Attempting to start $ConName
nmcli -t con up id "$ConName"
sleep 5
MT=C ifconfig | grep -q $IntCon
if [ $? -eq 0 ]; then
#error_count=0
i=$Good_connect_count
else
error_count=$[$error_count+1]
echo "$error_count Error(s) in a row"
fi
fi
else
dt=$(date)
echo At $dt we have no WWAN...attempting to Enable
nmcli -t nm wwan on
sleep 5
MT=C nmcli -t -f WWAN nm | grep -q "enabled"
if [ $? -eq 0 ]; then
error_count=$error_count
else
error_count=$[$error_count+1]
echo "$error_count Error(s) in a row"
fi
fi
else
dt=$(date)
echo At $dt we dont have our $ConType connection
echo Rebooting USB Device $USB_Vendor : $USB_Product
#Reset USB Modem
usb_modeswitch -Q -R -v $USB_Vendor -p $USB_Product
error_count=0
sleep 25
fi
if [ $error_count -ge 3 ]; then
dt=$(date)
echo We have an issue. Rebooting USB Device at $dt.
usb_modeswitch -Q -R -v $USB_Vendor -p $USB_Product
sleep 25
error_count=0
i=0
fi
i=$[$i+1]
if [ $i -ge $Good_connect_count ]; then
dt=$(date)
if [ $pingtest -eq 0 ]; then
MT=C ping -c1 $Default_ping_host | grep -q "64 bytes from"
if [ $? -eq 0 ]; then
echo At $dt connection is up and ping test passed!
#error_count=0
i=0
pingtest=1
else
echo Connection is present but cant confirm ping connectivity. Retrying...
error_count=$[$error_count+1]
echo "$error_count Error(s) in a row"
fi
else
pingtest=0
MT=C wget --spider http://www.hp.com 2>&1 | grep -q "200"
if [ $? -eq 0 ]; then
echo At $dt connection is up and http test passed!
error_count=0
i=0
else
echo Connection is present but cant confirm http connectivity. Retrying...
error_count=$[$error_count+1]
echo "$error_count Error(s) in a row"
fi
fi
fi
done