Tailing the latest Apache error log

When debugging web server errors, my first instict is to check Apache’s error logs.
After navigating to the apache error log directory, I just tail the error log.
While this should be relatively simple, when Apache rotates the logs it can be a
little more cumbersome because we have to find which log is the most recent.
This usually involves the following steps (assuming we are in the directory that
contains the Apache error logs):

First, we must find the most recent log:


ls -tr error*

This produces a list similar to this:


error_log.1289563200
error_log.1289908800
error_log.1289995200
error_log.1290168000
error_log.1292587200
error_log.1292803200
error_log.1292846400
error_log.1292932800
error_log.1294056000
error_log.1294228800

Since this ls command gives us the most recent log file at the bottom of the list, we can now go onto the next step:


tail -f error_log.1294228800

While this works everytime, it just seems as if its too many steps. Instead of following the above process, lets cut it down to one step:


tail -f $(ls -tr error* | tail -1)

With this approach, we don’t even need to know the name of the log… as it will pull the last one for us!

~ by ityndall on January 5, 2011.

2 Responses to “Tailing the latest Apache error log”

  1. You could take that one step further and create an alias; e.g.,

    alias tail-error=’tail -f $(ls -tr /path/to/apache/logs/error* | tail -1)’

    Put that in your ~/.bashrc, log out, and log back in, and then all you need to do is type tail-error (or whatever you name it). 🙂

  2. […] version 2.1.9.cp21 Simple Fix to Increase Comments on Your BlogNobel economists have no simple fixTailing the latest Apache error log […]

Leave a Reply