Skip to content

Instantly share code, notes, and snippets.

@digitalresistor
Last active November 13, 2016 18:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save digitalresistor/12ae691e5c285f334a36 to your computer and use it in GitHub Desktop.
Save digitalresistor/12ae691e5c285f334a36 to your computer and use it in GitHub Desktop.
Simple script that prints a list of redirects, and what the final HTTP result was...
function count_redir {
curl -L -I -D - -o /dev/null $1 | awk 'BEGIN { redir = 0; status = 200; } tolower($1) ~ /http/ { redir=redir+1; status=$2 } tolower($1) ~ /location:/ { print redir, status, $2 } END { print "Completed, with ", redir-1, "redirects. Final result: ", status }'
}
alexandra:~ xistence$ count_redir http://slate.me/1h0svt8
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 120 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 101 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 120 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 101 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 120 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 95 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
1 301 http://slate.trib.al/8OfbdvM
2 301 http://slate.me/1tByJQz
3 301 http://slate.trib.al/IOYnwof
4 301 http://slate.me/1kZ76jq
5 301 http://slate.trib.al/QjWEhrI
6 301 http://goo.gl/qF0xUk
7 301 http://www.slate.com/blogs/future_tense/2014/05/30/nyc_citi_bike_zero_fatalities_in_new_york_city_bike_share_program_s_first.html
Completed, with 7 redirects. Final result: 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment