Hi,I want to create a script for monitor internet connectivity

I want check both 8.8.8.8 and 223.5.5.5
But this script only check 8.8.8.8
Can anyone help me modify this script?Thanks a lot.

#!/bin/sh
#sleep 100
DATE=`date +%Y-%m-%d-%H:%M:%S`
tries=0
echo --- my_watchdog start ---
while [[ $tries -lt 5 ]]
do
        if /bin/ping -c 1 8.8.8.8 >/dev/null
        then
                echo --- exit ---
#               echo $DATE OK >>my_watchdog.log
                exit 0
        fi
        tries=$((tries+1))
        sleep 10
#       echo $DATE tries: $tries >>my_watchdog.log
done
 
echo $DATE network restart >>my_watchdog.log
/etc/init.d/network restart
echo $DATE mwan3 restart >>my_watchdog.log
/etc/init.d/mwan3 restart
sleep 30s 
echo $DATE AdGuardHome restart >>my_watchdog.log
/etc/init.d/AdGuardHome restart

 
#echo $DATE reboot >>my_watchdog.log
#reboot

Run two scripts?

1 Like
2 Likes

Let me try,thanks.

I need when internet down,Openwrt can restart network,mwan3 and Adguard-Home automatically.

I tested it, your solution worked. Just run two scripts. thank you very much. :grinning:

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

No need to write your own. There's already a service in Openwrt called watchcat that can monitor multiple IPs

2 Likes

There are two other scripts:

  1. this one uses http requests instead of pings (As sometimes ping can work but http doesn't): https://github.com/libremesh/lime-packages/tree/master/packages/check-internet
  2. watchping: https://github.com/libremesh/lime-packages/tree/master/packages/watchping
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.