From ea4dea861743ebbae4f2feed5941dde816e73075 Mon Sep 17 00:00:00 2001 From: tylen Date: Tue, 8 Jul 2025 22:40:32 +0300 Subject: [PATCH] router: correct a bug in the script - Corrected the service restart commands to use the proper syntax for stopping and starting the WAN interface. - Improved the ping test logic to return success or failure directly, simplifying the main script execution. - Enhanced error logging by redirecting standard error output to the log file during the ping test. - Streamlined the ping command to use the configured PING_HOST variable directly. - Ensured that the script properly handles return values from the ping test function. These changes improve the reliability and clarity of the WAN monitoring functionality. --- router/scripts/restart-wan | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/router/scripts/restart-wan b/router/scripts/restart-wan index 4f3385f..f42f518 100644 --- a/router/scripts/restart-wan +++ b/router/scripts/restart-wan @@ -26,10 +26,10 @@ ping_test() { wan_monitor "Running ping test..." while [ $count_tries -lt $MAX_TRIES ]; do - if /bin/ping -c 1 -W $PING_WAIT $@ >/tmp/wan_check.log; then + if /bin/ping -c 1 -W $PING_WAIT $PING_HOST >/tmp/wan_check.log 2>&1; then ping_test_passed=1 wan_monitor "Ping test succeeded within $PING_WAIT secs." - exit 0 + return 0 # Return success else sleep 1 count_tries=$((count_tries + 1)) @@ -37,12 +37,11 @@ ping_test() { fi done - return $ping_test_passed + return 1 # Return failure } - - -if [ $(ping_test $PING_HOST) -gt 0 ]; then +# Main script execution +if ping_test; then wan_monitor "Internet was reachable. No need to restart WAN." else wan_monitor "Pings failed. Internet must be down." @@ -50,3 +49,4 @@ else fi +