#!/bin/sh
printf "Start at `date`\n"
while true; do
state=`nmcli -f device,state device | grep ttyUSB2 | awk '{ print $2 }'`
if [ "$state" = "disconnected" ]; then
result=`nmcli device connect ttyUSB2 | grep 'Unknown error'`
if [ "$result" ]; then
echo "Device connect failed, need reset usb device"
sleep 1
/root/bin/reset-ttyUSB2
count=0
while [ "$count" -lt 60 ]; do
printf "[$count]\r"
state=`nmcli -f device,state device | grep ttyUSB2`
[ "$state" ] && printf "\nGSM back '$state' at `date`\n" && break
count=`expr $count + 1`
sleep 1
done
if [ "$count" -eq 60 ]; then
echo "Hmmm, after waiting for $count secs, GSM device still not back"
echo "Do we need to reboot the system?"
exit
fi
else
echo "=== Connect return no error ==="
nmcli device | grep ttyUSB2
sleep 1
fi
else
echo -n "."
sleep 10
fi
done
Comments