Skip to content

Instantly share code, notes, and snippets.

@alxf
Created July 10, 2012 13:05
Show Gist options
  • Save alxf/3083119 to your computer and use it in GitHub Desktop.
Save alxf/3083119 to your computer and use it in GitHub Desktop.
Script to output 404 request summary per virtualhost.
#!/bin/dash
# Parse access log from a virtual host and output 404 requests.
# Logfile is $LOGDIR/host1.domain.tld/access.log for example.
# If you want this report by mail, set a crontab:
#
# 0 22 * * * 404stats.sh | mail -s "404 report" mail@domain.tld
#
#apache log directory
LOGDIR="/var/log/apache2"
#virtual host domains log directories
SITENAMES="\
host1.domain.tld
host2.domain.tld
"
for www in $SITENAMES; do
output=$(awk '{if ($9 == 404) {print $7}}' $LOGDIR/$www/access.log \
| sort -rn | uniq -c | sort -rn)
if [ -n "$output" ]; then
echo " * 404 pages for http://$www"
echo ""
echo "$output"
else
echo " * no 404 request for http://$www"
fi
echo ""
done
echo "-- "
echo "$(basename $0)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment