Select Page
Hi All,

Script is working as expected. I modified it to how i need it. There were some mistakes which i worked out and corrected. Here is my script. You do need to make it executable.

You firstly need to vi and create the file.

sudo vi /config/scripts/check-connection.sh

Paste in my below script and then press alt : and wq (enter) to save it.

Now make it executable

sudo chmod +x /config/scripts/check-connection.sh

Now make put this into task scheduler

TASK 
show system task-scheduler
task check-connection {
executable {
path /config/scripts/check-connection.sh
}
interval 5m
}

SCRIPT

#!/bin/bash
Message from syslogd@bexleypark-ubnt at Sep 20 11:48:24 …nough logs
kernel:unregister_netdevice: waiting for pppoe0 to become free. Usage count = 185
if [ ! -e ${LOG} ]; then
seq 1 1000 > ${LOG}
fi
# Remove the older log from the file
sed -i 1d ${LOG}
### First check
/bin/ping -w 2 -c 2 -s 1 1.1.1.1 > /dev/null 2> /dev/null
if [ “$?” == “0” ]; then
RES=0
else
RES=1
fi
### Second check
/bin/ping -w 2 -c 2 -s 1 8.8.8.8 > /dev/null 2> /dev/null
if [ “$?” == “0” ]; then
RES=$((RES+0))
else
RES=$((RES+1))
fi
### Result
if [ “$RES” == “0” ]; then
echo “$(date) –> CONNECTION OK” >> ${LOG}
exit 0
elif [ “$RES” == “1” ]; then
echo “$(date) –> CONNECTION OK BUT ONE REMOTE HOST TESTED IS DOWN” >> ${LOG}
exit 0
else
echo “$(date) –> CONNECTION FAILURE DETECTED” >> ${LOG}
/opt/vyatta/bin/vyatta-op-cmd-wrapper clear interfaces connection pppoe0
/bin/sleep 30
/usr/bin/curl ‘https://api.simplepush.io/send/xxx/Router/PPP restarted because connection stuck’
fi