#!/bin/bash smbcheck=0 echo "begin ping" while [ $smbcheck -ne 1 ]; do ping -c 2 10.11.13.254 if [ $? -eq 0 ]; then echo "ping success"; mount -a smbcheck=1; else echo "fail ping" fi done echo "fin script ====== sample 2 ====== #!/bin/sh # ping mullvad dns that can only be reached via the VPN tunnel # if no contact, reboot! tries=0 while [[ $tries -lt 5 ]] do if /bin/ping -c 1 10.64.0.1 then echo "wg works" exit 0 fi echo "wg fail" tries=$((tries+1)) done echo "wg failed 5 times - rebooting" reboot ====== wg ping restart interface ====== #!/bin/sh #modified from https://openwrt.org/docs/guide-user/base-system/cron #modified to use logger for global logging instead of scriptlogfile & added infinite reboot protection for reboot # Prepare vars DATE=$(date +%Y-%m-%d" "%H:%M:%S) #logFile="/persistlogs/syslog" # Ping and reboot if needed #YOUR WIREGUARD PEER CHECKHOSTNAME="172.17.16.1" notification_email="bxxxxx@gmail.com" VPNINTERFACE="wg0" ping -c3 $CHECKHOSTNAME if [ $? -eq 0 ]; then echo "ok" logger $(echo "${DATE} - $0: OK - $VPNINTERFACE UP AND RUNNING") else echo "RESTART wgvpn0 Interface" logger $(echo "${DATE} - $0: NO VPN CONNECTION RESTART $VPNINTERFACE INTERFACE...") # Note: To avoid infinite reboot loop, wait 70 seconds and touch a file in /etc ifdown $VPNINTERFACE ifup $VPNINTERFACE echo Subject: $0: VPN $VPNINTERFACE has been restarted | sendmail -v "$notification_email" fi