Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created November 30, 2012 08:40
Show Gist options
  • Select an option

  • Save jeffreyiacono/4174553 to your computer and use it in GitHub Desktop.

Select an option

Save jeffreyiacono/4174553 to your computer and use it in GitHub Desktop.
simple script that uses pinger + sendmail to notify you of a pinger failure for a given set of urls
#!/bin/bash
# usage:
#
# ./pinger-notifier.sh url_1 [url_2 ...]
#
# this use https://github.com/jeffreyiacono/pinger and assumes
# it's setup via the command line (see: https://github.com/jeffreyiacono/pinger#usage)
set -e
for url in "$@"; do
if ! msg=$(pinger $url) ; then
email=$(cat <<EOS
From: You <[email protected]>
To: [email protected]
Subject: pinger alert for $1 @ $(date "+%Y-%m-%d %H:%M:%S")
Content-Type: text/html; charset=utf-8
Content-Disposition: inline;
<p>
<h2>$url => $msg</h2>
<p>result from <code>$ pinger $1</code> @ $(date "+%Y-%m-%d %H:%M:%S")</p>
</p>
EOS
)
echo -e "$email" | /usr/sbin/sendmail -t
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment