Skip to content

Instantly share code, notes, and snippets.

@RWJMurphy
Last active December 11, 2015 11:09
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 RWJMurphy/4592166 to your computer and use it in GitHub Desktop.
Save RWJMurphy/4592166 to your computer and use it in GitHub Desktop.
A fast, `parallel` powered website status checking script.
#!/bin/bash
check="./check_host.sh"
logfile="lastrun.log"
debug=$1
if command -v parallel >/dev/null 2>&1; then # PARALLEL :D
cat hosts | parallel --joblog $logfile -a - -j '1000%' "$check {} $debug"
else # NOT PARALLEL D:
rm -f $logfile && touch $logfile
for host in $(cat hosts); do
[ "$host" == "" ] && continue
$check $host $debug | tee -a $logfile
done
fi
#!/bin/bash -e
[ "$1" == "" ] && echo "$0 <hostname>" && exit 2
check_dns() {
hostname=$1
debug=$2
if host $hostname >/dev/null; then :; else
echo $hostname failed DNS lookup
if [ "$debug" != "" ]; then
dig +trace @8.8.8.8 $hostname
fi
fi
}
check_http() {
hostname=$1
debug=$2
if curl -m 10 -LIs $hostname >/dev/null; then :; else
echo $hostname failed HTTP request
if [ "$debug" != "" ]; then
curl -m 10 -sS -v -L $hostname
curlcode=$?
case $curlcode in
7) # Failed to connect() to host or proxy
traceroute -n $hostname
;;
esac
fi
fi
}
check_dns $1 $2
check_http $1 $2
example.com
www.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment