Last active
December 11, 2015 11:09
-
-
Save RWJMurphy/4592166 to your computer and use it in GitHub Desktop.
A fast, `parallel` powered website status checking script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example.com | |
www.example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment