Skip to content

Instantly share code, notes, and snippets.

@realdubb
Forked from lkptrzk/404-check.sh
Created November 18, 2016 02:10
Show Gist options
  • Save realdubb/227504678024a79c759d886c7464cd0f to your computer and use it in GitHub Desktop.
Save realdubb/227504678024a79c759d886c7464cd0f to your computer and use it in GitHub Desktop.
Script to test for 404s
#!/bin/sh
# 404-check.sh - Script to test for 404s
# author: lkptrzk
# Usage:
# Assuming a file named 'input' with one URL per line
# the following command will output which files were 404s:
# cat input | xargs 404-check.sh
# Notes:
# curl -I = only get headers
# 2>/dev/null = prevent stderr from going through the pipe
# (causes problems when piping curl)
# head -1 = HTTP response code should be first line of output from curl
for arg in $@ ; do
currUrl=$arg
curl -I 2>/dev/null $currUrl | head -1 | grep 404 >/dev/null
if [ $? == 0 ] ; then
echo $currUrl
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment