stable #2
@@ -1,22 +1,46 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
log_file="/var/log/watchdog.log"
|
||||||
|
|
||||||
|
# Extract watchdog IP addresses
|
||||||
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"
|
IFS=' ' read -r -a ip_array <<< "$watchdog"
|
||||||
|
|
||||||
|
# Configuration file
|
||||||
config_file="/etc/watchdog.conf"
|
config_file="/etc/watchdog.conf"
|
||||||
sudo cp "$config_file" "$config_file.bak"
|
|
||||||
|
# Backup current configuration
|
||||||
|
if sudo cp "$config_file" "$config_file.bak"; then
|
||||||
|
echo "Backup of $config_file created successfully." >> "$log_file"
|
||||||
|
else
|
||||||
|
echo "Failed to create backup of $config_file." >> "$log_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean existing configurations
|
||||||
sudo sed -i '/ping/d' "$config_file"
|
sudo sed -i '/ping/d' "$config_file"
|
||||||
sudo sed -i '/^interval/d' "$config_file"
|
sudo sed -i '/^interval/d' "$config_file"
|
||||||
|
|
||||||
|
# Set interval
|
||||||
echo "interval = 60" | sudo tee -a "$config_file" > /dev/null
|
echo "interval = 60" | sudo tee -a "$config_file" > /dev/null
|
||||||
|
|
||||||
if [ ${#ip_array[@]} -eq 0 ]; then
|
if [ ${#ip_array[@]} -eq 0 ]; then
|
||||||
sudo sed -i '/interval/d' "$config_file"
|
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
|
||||||
echo "No IP addresses found. Watchdog configuration cleared." >> /var/log/watchdog 2>&1
|
|
||||||
sudo systemctl stop watchdog
|
sudo systemctl stop watchdog
|
||||||
else
|
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
|
||||||
done
|
done
|
||||||
|
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart watchdog service
|
||||||
|
if sudo systemctl restart watchdog; then
|
||||||
|
echo "Watchdog service restarted successfully." >> "$log_file"
|
||||||
|
else
|
||||||
|
echo "Failed to restart watchdog service." >> "$log_file"
|
||||||
fi
|
fi
|
||||||
sudo systemctl restart watchdog >> /var/log/watchdog 2>&1
|
|
||||||
|
|
||||||
# Version 1.1:
|
# Version 1.1:
|
||||||
# Created 2024 by Tim Eertmoed @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.
|
# Created 2024 by Tim Eertmoed @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.
|
||||||
|
|||||||
Reference in New Issue
Block a user