Skip to content

Instantly share code, notes, and snippets.

@phunehehe
Last active December 23, 2018 00:54
Show Gist options
  • Save phunehehe/5564090 to your computer and use it in GitHub Desktop.
Save phunehehe/5564090 to your computer and use it in GitHub Desktop.
Script to check multiple URLs in Nagios, see http://phunehehe.net/check-multiple-urls-nagios/
#!/bin/bash
# Split URLs by comma
urls=${1//,/ }
for url in $urls
do
hostname="${url%%/*}"
if [[ "$url" = */* ]]
then
# Domain plus path, like example.com/path
path="/${url#*/}"
else
# Just domain, like example.com
path=/
fi
result="$(/usr/lib/nagios/plugins/check_http --hostname "$hostname" --url "$path")"
status="$?"
if [[ "$status" -ne 0 ]]
then
# First warning is the final result
echo "$url: $result"
exit "$status"
fi
done
echo "All URLs OK: $urls"
@rkperumala
Copy link

I can't either get this to work. I have a bunch of URL's. It shows All Urls OK even when given a wrong URL in the $urls !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment