Switch to Normal Style Sheet
Site Icon The Lab Book Pages Andrew Greensted (Modified: 25 July 2007)
Web > Admin

Admin

Bits n' bobs related to web server admin and maintenance.

Divider Bar Go to page top

• Apache Sub Directory Log Filter

If your website sits under a subdirectory of a larger website, then A LOT of the server's logs are not that relavent to your site. This one liner can be used to filter out all the logs that are not important, leaving entries related to your site, and with the parent directories removed from the request path.

To use, replace the text /some/where (keeping the ^) with the path to your site, and adjust the second argument in the substr function (currently 12) to the length of the path text + 1. Running the command redirects the filtered logs to a file called filtered.

> awk '{ if ($7 ~ "^/some/where" ) { $7=substr($7,12,length($7)); \
  print $0 } }' access_log > filtered

Note: This command relies on the 7th column in the log file containing the requested resource, i.e. the page/image/file being fetched from the server. If your server is set to log differently then you'll need to change the column number awk is checking.

Divider Bar Go to page top