From 63a40835b6d9099d1b407a2c5c79075614299861 Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Mon, 28 Oct 2024 19:58:33 +0100 Subject: [PATCH] usr/bin/custom/watchdog-monitor aktualisiert --- usr/bin/custom/watchdog-monitor | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/usr/bin/custom/watchdog-monitor b/usr/bin/custom/watchdog-monitor index 1d9ef72..43eb4ce 100644 --- a/usr/bin/custom/watchdog-monitor +++ b/usr/bin/custom/watchdog-monitor @@ -11,8 +11,9 @@ update_watchdog_config() { # Extract watchdog IP addresses watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \ awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";') - - IFS=' ' read -r -a ip_array <<< "$watchdog" + + # Split the watchdog IPs into an array + IFS=',' read -r -a ip_array <<< "$watchdog" # Backup current configuration if sudo cp "$config_file" "$config_file.bak"; then @@ -28,27 +29,27 @@ update_watchdog_config() { # Set interval echo "interval = 59" | sudo tee -a "$config_file" > /dev/null - if [ ${#ip_array[@]} -eq 0 ]; then - echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file" - else + # Check if IP addresses are found and add them to the config + if [ ${#ip_array[@]} -gt 0 ]; then for ip in "${ip_array[@]}"; do echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null + echo "Configured watchdog to ping: $ip" >> "$log_file" done - echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file" - + # Restart watchdog service since IP addresses were found if sudo systemctl restart watchdog; then echo "Watchdog service restarted successfully." >> "$log_file" else echo "Failed to restart watchdog service." >> "$log_file" fi - return 1 # Indicate that IP addresses were found fi + echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file" return 0 # Indicate that no IP addresses were found } + # Main loop start_time=$(date +%s) end_time=$((start_time + 300)) # 5 minutes in seconds