Hello,
I'm using the following scripts to ensure connectivity but is it possible those will end up in a boot loop or similar if there is no internet connection?
at crontab -e I inserted a job all 30 min to start 4G-restart-interface.sh
#---------------root@OpenWrt:~# cat 4G-keep-alive.sh--------------------------
#------------------------------------------------------------------------------------
#!/bin/ash
# The main script file. I recommend putting into cron, e.g.:
# */2 * * * * /root/4G-keep-alive.sh
DIR=$( cd $(dirname $0) ; pwd -P )
LOG_FILE="$DIR/log-4G.txt"
OFFLINE_COUNT=$(cat $LOG_FILE | tail -4 | grep OFFLINE | wc -l)
OFFLINE_COUNT_TRESHOLD=4
SH_DNS_TESTS="$DIR/4G-dns-test.sh"
SH_RESTART_INTERFACE="$DIR/4G-restart-interface.sh"
SH_RESTART_ROUTER="$DIR/restart-router.sh"
LINES_MAX=11000
LINES_MIN=6000
LINES_COUNT=$(wc -l $LOG_FILE | awk '{print $1}')
# if the log files gets huge, strip it, keep last LINES_MIN lines
if [[ "$LINES_COUNT" -ge "$LINES_MAX" ]]; then
echo "$(tail -$LINES_MIN $LOG_FILE)" > $LOG_FILE
fi
# DNS test, it's result defines the ONLINE/OFFLINE state
`$SH_DNS_TESTS`
if [ $? -eq 1 ]; then
echo "Ooops, LTE network is down!"
echo "$(date) OFFLINE > RESTARTING INTERFACE" >> $LOG_FILE
if [[ "$OFFLINE_COUNT" -ge "$OFFLINE_COUNT_TRESHOLD" ]]; then
echo ">> Restarting router.." >> $LOG_FILE
$SH_RESTART_ROUTER
else
echo ">> Restarting LTE interface.." >> $LOG_FILE
$SH_RESTART_INTERFACE
fi
else
echo "LTE is okay!"
echo "$(date) ONLINE" >> $LOG_FILE
fi
#------------------root@OpenWrt:~# cat 4G-dns-test.sh-----------------------------
#------------------------------------------------------------------------------------
#!/bin/ash
# This file is responsible for DNS check. The return value of its process
# determines the ONLINE/OFFLINE state.
IP_TO_PING=8.8.8.8
PACKET_COUNT=4
ONLINE=0
for i in `seq 1 $PACKET_COUNT`;
do
nc -G 2 -z $IP_TO_PING 53
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
ONLINE=1
fi
done
if [ $ONLINE -eq 1 ]; then
# ONLINE
exit 0
else
# OFFLINE
exit 1
fi
#------------------------------------------------------------------------------------
#-----------------root@OpenWrt:~# cat 4G-restart-interface.sh---------------------------
#------------------------------------------------------------------------------------
#!/bin/ash
# This file is responsible for restarting the network interface.
# Should be run once OFFLINE state is detected.
INTERFACE="4G"
# syslog entry
logger -s "INTERNET KEEP ALIVE SYSTEM: Restarting the LTE interface."
echo "SH RESTART IFACE DOWN"
ifdown $INTERFACE
sleep 2
echo "SH RESTART IFACE UP"
ifup $INTERFACE
#sleep 4
#------------------------------------------------------------------------------------
#------------------root@OpenWrt:~# cat restart-router.sh-----------------------------
#------------------------------------------------------------------------------------
#!/bin/ash
# This file is responsible for restarting the router using reboot command.
# There is a stratery to write few lines into the log, so that grepping last lines
# returns less occurences of word OFFLINE. Too many occurences actually run this script.
DIR=$( cd $(dirname $0) ; pwd -P )
LOG_FILE="$DIR/log.txt"
echo "$(date) > TOO MANY OFFLINE TRYOUTS" >> $LOG_FILE
echo "$(date) > GOING TO REBOOT NOW" >> $LOG_FILE
echo "$(date) > NOW!" >> $LOG_FILE
echo "$(date) > SORRY FOR ANY INCONVENIENCE." >> $LOG_FILE
echo "SH REBOOT"
reboot