Last active
June 7, 2023 09:07
-
-
Save Salamandar/41777e501ee8607111c0cc438ba3031b to your computer and use it in GitHub Desktop.
send email if an host is not pingable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuo pipefail | |
HOSTS_TO_CHECK=( | |
127.0.0.1 | |
github.com | |
test_invalid.com | |
) | |
test_host() { | |
host=$1 | |
ping -W 1 -c 1 "$host" >/dev/null || return 1 | |
} | |
send_email() { | |
hosts_down=$@ | |
# echo "Those hosts are down: ${HOSTS_DOWN[*]}" | |
raid_control --test-alert | |
} | |
HOSTS_DOWN=() | |
for host in "${HOSTS_TO_CHECK[@]}"; do | |
if ! test_host "$host"; then | |
HOSTS_DOWN+=("$host") | |
fi | |
done | |
if (( "${#HOSTS_DOWN[*]}" != 0 )); then | |
send_email "${HOSTS_DOWN[@]}" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment