What's new

How to properly configure Chk-WAN script with cron?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

andresmorago

Senior Member
Hello

Im trying to configure @Martineau Chk-WAN script. My desired behavior is to run the script every 10 minutes and to restart WAN when connection fails.
According to the wiki, I should use this cron script but i notice that the cron flag with reboot router instead of just the wan connection.

Code:
cat > /jffs/scripts/wan-event << EOF;chmod +x /jffs/scripts/wan-event
#!/bin/sh

if [ "\$2" == "connected" ];then
    sh /jffs/scripts/ChkWAN.sh ping=1.1.1.1,8.8.8.8 cron="\*/10 \* \* \* \*" &
fi
EOF

Code:
#           ChkWAN  cron
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 30mins.
#                   'cru a ChkWAN "*/30 * * * * /jffs/scripts/ChkWAN.sh"'
#
#           ChkWAN  cron=\*/5
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 5mins.
#                   'cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh"'
#                   NOTE: You need to escape the '*' on the commandline :-(
 
Hello

Im trying to configure @Martineau Chk-WAN script. My desired behavior is to run the script every 10 minutes and to restart WAN when connection fails.
According to the wiki, I should use this cron script but i notice that the cron flag with reboot router instead of just the wan connection.

Code:
cat > /jffs/scripts/wan-event << EOF;chmod +x /jffs/scripts/wan-event
#!/bin/sh

if [ "\$2" == "connected" ];then
    sh /jffs/scripts/ChkWAN.sh ping=1.1.1.1,8.8.8.8 cron="\*/10 \* \* \* \*" &
fi
EOF

Code:
#           ChkWAN  cron
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 30mins.
#                   'cru a ChkWAN "*/30 * * * * /jffs/scripts/ChkWAN.sh"'
#
#           ChkWAN  cron=\*/5
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 5mins.
#                   'cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh"'
#                   NOTE: You need to escape the '*' on the commandline :-(
Add the wan directive to the cron scheduled command (see First example shown by the help)

e.g.
Bash:
if [ "\$2" == "connected" ];then
    sh /jffs/scripts/ChkWAN.sh wan ping=1.1.1.1,8.8.8.8 cron="\*/10 \* \* \* \*" &
fi
Code:
ChkWAN.sh help

#============================================================================================ © 2016-2022 Martineau v1.17
#
# Monitor WAN connection state using PINGs to multiple hosts, or a single cURL 15 Byte data request and optionally a 12MB/500B WGET/CURL data transfer.
#         NOTE: The cURL data transfer rate/perfomance threshold may also be checked e.g. to switch from a 'slow' (Dual) WAN interface.
#         Usually the Recovery action (REBOOT or restart the WAN) occurs in about 90 secs (PING ONLY) or in about 03:30 mins for 'force' data download
#
# Usage:    ChkWAN  [help|-h]
#                   [reboot | wan | noaction] [force[big | small]] [nowait] [quiet] [once] [i={[wan0|wan1]}] [googleonly] [curl] [ping='ping_target[,..]']
#                   [tries=number] [fails=number] [curlrate=number] [verbose] [cron[=[cron_spec]]] [status] [stop
#
#           ChkWAN
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS
#           ChkWAN  force
#                   Will REBOOT router if the PINGs to ALL of the hosts FAIL, but after each group PING attempt, a physical 12MByte data download is attempted.
#           ChkWAN  forcesmall
#                   Will REBOOT router if the PINGs to ALL of the hosts FAIL, but after each group PING attempt, a physical 500Byte data download is attempted.
#                   (For users on a metered connection assuming that the 15Byte cURL is deemed unreliable?)
#           ChkWAN  status
#                   Will report if Check WAN monitor is running
#           ChkWAN  wan
#                   Will restart the WAN interface (instead of a FULL REBOOT) if the PINGs to ALL of the hosts FAIL
#           ChkWAN  stop
#                   Will request termination of script. It will be dependent on the 'sleep' interval
#                   NOTE: If scheduled by cron this will have no effect.
#           ChkWAN  curl
#                   Will REBOOT router if cURL (i.e. NO PINGs attempted) fails to retrieve the remote end-point IP address of the WAN (Max 15bytes)
#           ChkWAN  cron
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 30mins.
#                   'cru a ChkWAN "*/30 * * * * /jffs/scripts/ChkWAN.sh"'
#           ChkWAN  cron=\*/5
#                   Will REBOOT router if the PINGs to ALL of the hosts FAILS, cron entry is added: Runs every 5mins.
#                   'cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh"'
#                   NOTE: You need to escape the '*' on the commandline :-(
#           ChkWAN  nowait
#                   By default the script will wait 10 secs before actually starting the check; 'nowait' (when used by cron) skips this delay.
#           ChkWAN  googleonly
#                   Only the two Google DNS severs will be PING'd - WAN Gateway/local DNS config will be ignored
#           ChkWAN  i=wan1 noaction
#                   In a Dual-WAN environment check WAN1 interface, but if it's DOWN simply return RC=99
#           ChkWAN  ping=1.2.3.4,1.1.1.1
#                   PING the two hosts 1.2.3.4 and 1.1.1.1, rather than the defaults.
#           ChkWAN  tries=1 fails=1
#                   Reduce the number of retry attempts to 1 instead of the default 3 and maximum number of fails is 1 rather than 3
#           ChkWAN  force curlrate=1000000
#                   If the 12MB average curl transfer rate is <1000000 Bytes per second (1MB), then treat this as a FAIL
#           ChkWAN  curl verbose
#                   The 'verbose' directive applies to any cURL transfer, and will display the cURL request data transfer as it happens
#
# Cron schedule may be reset /jffs/scripts/ChkWAN_Reset_CRON.sh if you have:
#
#      Set up a static cron schedule every 10 minutes 2 times WAN Restart 3rd REBOOT
#              cru a Restart_WAN 00,10,30,40 * * * * /jffs/scripts/ChkWAN.sh wan force nowait
#              cru a Reboot_WAN 20,50 * * * * /jffs/scripts/ChkWAN.sh reboot force nowait
#      but /jffs/scripts/ChkWAN_Reset_CRON.sh can change after very successful WAN UP check (Syslog monitor is better!!!?)
#               cru a Restart_WAN 28,38,58,8 * * * * /jffs/scripts/ChkWAN.sh wan force nowait
#               cru a Reboot_WAN 48,18 * * * * /jffs/scripts/ChkWAN.sh reboot force nowait
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top