webSIGHTdesigns - Web Design, Web Development, Web Hosting

Bash Script to Tail Apache Logs

Posted on Wednesday, November 13th, 2013 at 12:30 am
by webSIGHTdesigns

Use this simple Bash script to easily tail Apache access and error logs.

To create a command to easily tail log files, create a new file:

$ vi /usr/sbin/log

Enter the following Bash script in the file:

#!/bin/bash
LOGPATH="/var/log/httpd/"
if [ "$1" = 'a' ]; then
    clear;tail -f -n0 $LOGPATH$2-access_log
elif [ "$1" = 'e' ]; then
    clear;tail -f -n0 $LOGPATH$2-error_log
else
    echo 'log - a simple command to view Apache access and error logs for a domain'
    echo 'syntax: log <a|e>'
    echo 'example: log a domain.com'
fi

Now make the file executable:

$ chmod +x /usr/sbin/log

The above is intended to be performed by a user with system administrator privileges. Once the new script is configured, admin users can run the command log a domain.com to tail access logs and the command log e domain.com to tail error logs.

Please Sign In

Please sign in to post a comment.

Web Development

View details »

Web Hosting

View details »

Our Portfolio

View portfolio »

WebSight Designs webSIGHTdesigns preferred email webSIGHTdesigns United States United States