stable #2
@@ -12,7 +12,8 @@ update_watchdog_config() {
|
|||||||
watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \
|
watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \
|
||||||
awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";')
|
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
|
# Backup current configuration
|
||||||
if sudo cp "$config_file" "$config_file.bak"; then
|
if sudo cp "$config_file" "$config_file.bak"; then
|
||||||
@@ -28,13 +29,12 @@ update_watchdog_config() {
|
|||||||
# Set interval
|
# Set interval
|
||||||
echo "interval = 59" | sudo tee -a "$config_file" > /dev/null
|
echo "interval = 59" | sudo tee -a "$config_file" > /dev/null
|
||||||
|
|
||||||
if [ ${#ip_array[@]} -eq 0 ]; then
|
# Check if IP addresses are found and add them to the config
|
||||||
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
|
if [ ${#ip_array[@]} -gt 0 ]; then
|
||||||
else
|
|
||||||
for ip in "${ip_array[@]}"; do
|
for ip in "${ip_array[@]}"; do
|
||||||
echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null
|
echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null
|
||||||
|
echo "Configured watchdog to ping: $ip" >> "$log_file"
|
||||||
done
|
done
|
||||||
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
|
|
||||||
|
|
||||||
# Restart watchdog service since IP addresses were found
|
# Restart watchdog service since IP addresses were found
|
||||||
if sudo systemctl restart watchdog; then
|
if sudo systemctl restart watchdog; then
|
||||||
@@ -42,13 +42,14 @@ update_watchdog_config() {
|
|||||||
else
|
else
|
||||||
echo "Failed to restart watchdog service." >> "$log_file"
|
echo "Failed to restart watchdog service." >> "$log_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1 # Indicate that IP addresses were found
|
return 1 # Indicate that IP addresses were found
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
|
||||||
return 0 # Indicate that no IP addresses were found
|
return 0 # Indicate that no IP addresses were found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
start_time=$(date +%s)
|
start_time=$(date +%s)
|
||||||
end_time=$((start_time + 300)) # 5 minutes in seconds
|
end_time=$((start_time + 300)) # 5 minutes in seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user