Created
August 19, 2016 00:57
-
-
Save mahemoff/72868c283c3aa657c633d2d720925702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# WEB | |
# e.g. webcheck /about google.com google.co.uk | |
# will check each host in parallel, multiple times | |
function webcheck { | |
trap handle_sigint SIGINT | |
set +m | |
path=$1 | |
shift | |
hosts=$* | |
for host in $hosts ; do | |
( | |
url="$host$path" | |
message="$url\n" | |
for i in {1..5}; do | |
start=`ruby -e 'puts Time.now.to_f'` | |
result=$(curl --silent -I $url | head -1) | |
end=`ruby -e 'puts Time.now.to_f'` | |
duration=$(bc <<< "$end-$start") | |
message="$message$i. $duration -> $result\n" | |
done | |
printf "$message\n" | |
) & | |
done 2>/dev/null | |
wait | |
} | |
# http://stackoverflow.com/a/7817949/18706 | |
function handle_sigint() { | |
for proc in `jobs -p` ; do kill $proc ; done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment