Created
May 6, 2012 21:57
-
-
Save martinemmert/2624753 to your computer and use it in GitHub Desktop.
checks urls redirects from a text file
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 | |
# clear the terminal | |
clear | |
# define some colors | |
txtred=$(tput setaf 1) | |
txtgreen=$(tput setaf 2) | |
txtrst=$(tput sgr0) | |
# counter | |
clear_count=0 | |
error_count=0 | |
# error codes | |
err_code=404 | |
# output header | |
echo "http code|test url|redirect target|num redirects|time redirect|time total" >> $2 | |
while read line | |
do | |
result=$(curl --write-out "%{http_code}|${line}|%{redirect_url}|%{num_redirects}|%{time_redirect}|%{time_total}" --silent --output /dev/null $line) | |
http_code=${result:0:3} | |
if [ $http_code -eq $err_code ]; | |
then | |
let error_count++ | |
echo ${txtred}$http_code${result:3}${txtrst} | |
else | |
let clear_count++ | |
echo ${txtgreen}$http_code${result:3}${txtrst} | |
fi | |
echo $result >> $2 | |
done <$1 | |
## output the result | |
echo | |
echo "results: ${txtgreen}${clear_count} passed${txtrst}/${txtred}${error_count} failed${txtrst}" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment