usr/bin/custom/watchdog-monitor aktualisiert
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user