Skip to content

Instantly share code, notes, and snippets.

@Salamandar
Last active June 7, 2023 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Salamandar/41777e501ee8607111c0cc438ba3031b to your computer and use it in GitHub Desktop.
Save Salamandar/41777e501ee8607111c0cc438ba3031b to your computer and use it in GitHub Desktop.
send email if an host is not pingable
#!/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