Add Bash and curl way

This commit is contained in:
Jeffrey Serio 2023-10-25 09:53:15 -05:00
parent 213cc81f51
commit 2617224d2e

View File

@ -72,3 +72,28 @@ sudo -u user /home/user/go/bin/go-uptime-alert >> "${LOGFILE}" 2>&1
- Send output to a static HTML file and format appropriately for web server. - Send output to a static HTML file and format appropriately for web server.
- Send output to a .md file for use in Hugo or other static site generators. - Send output to a .md file for use in Hugo or other static site generators.
## Or just use Bash and curl
``` shell
#!/usr/bin/env bash
# associative array to store mappings between site URLS and ping URLs.
declare -A sites_hc_urls
sites_hc_urls["https://hyperreal.coffee"]="https://healthchecks.io/ping/blahblah"
sites_hc_urls["https://anonoverflow.hyperreal.coffee""]="https://healthchecks.io/ping/blahblahblah"
...
for key in "${!sites_hc_urls[@]}"; do
if curl -sSL -q "$key" >/dev/null 2>&1; then
if curl -m 10 --retry 5 "${sites_hc_urls[$key]}" >/dev/null 2>&1; then
echo "$key: OK"
else
echo "Error sending ping to ${sites_hc_urls[$key]}"
fi
else
echo "$key: DOWN"
fi
done
```