Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am real-time monitoring my website log, but would like to create a script that shows only the following in nice pretty columns.

log being used: /var/log/httpd/access_log (default log file and settings)

Host Name - IP Address - Page - Date & Time

Current command being used via Terminal: tail -f /var/log/httpd/access_log | awk '{ print "hostname" $1 $7 $4 }'

I have found someone that created what i am trying to do, but they have not responded to me. Here is screen shot of what i would like to end up with

http://qph.cf.quoracdn.net/main-qimg-fde4d84bf459d14aff0ef930e4f8c7fe

Also would like to incorporate netstat -anp | grep :80 | wc -l into the script at the top to show current connection count

My current output is garbled as shown below:

IPPAGETIME

with no separations etc...

I am new to scripting in general so this is all new to me and took me a bit to get awk to work for me, if there is a post with this already please share

    #!/bin/sh

    # Define some variables#
    TAIL="/usr/bin/tail -f"
    # TAIL command can also be -10, -15, -20, -30
    LOG="/var/log/httpd/access_log"
    TOTAL=`netstat -pant | grep :80 | wc -l`
    TOTAL2=`netstat -pant | grep :443 | wc -l`
    echo "There are $TOTAL port 80 connections."
    echo "There are $TOTAL2 port 443 connections."
    uptime | awk '{print $8,$9,$10,$11,$12,$13,$14,$15}'

    #Let's do it#
    $TAIL $LOG | awk '{print$3 " " $8 " " $4 " " $6 " " $8 " " $9 " " $7}'

    #DONE
share|improve this question
    
What have you tried? You do not specify what your 'real-time monitoring' is now. –  Bort Feb 5 '13 at 19:51
    
tail -f /var/log/httpd/access_log | awk '{ print "hostname" $1 $7 $4 }' –  user157574 Feb 5 '13 at 20:00

2 Answers 2

up vote 0 down vote accepted

@Stephan fancy putting the link to the original question?

user157574

You will want to use printf or tput with column most likely. Using these works for me, although I realise it is not real time:

less access_log | grep 05/Feb/2013 | awk '{print $1,$4,$7;}'

less access_log | grep 05/Feb/2013 | awk '{ x = $2 " " $4 " " $7 ; printf "%-15s %-20s \n", $1, x, $7}'

Edit:

You can try a changed version of this:

#!/bin/bash
ACCESSLOG="/var/log/apache2/access_log"
TOTAL=`netstat -pant | grep :80 | wc -l`

echo "There are a total of $TOTAL port 80 connections."
uptime | awk '{print $8,$9,$10,$11,$12}'

tail -5 $ACCESSLOG | grep "05/Feb/2013" | awk '{ x = $2 " " $4 " " $7 ; printf "%-15s %-20s \n", $1, x, $7}'

You could edit it to either tail -f so it is live or tail -5 , -10 , -20 etc.

share|improve this answer
    
i will give it a try, in the end i am as mentioned in both posts trying to create a shell script –  user157574 Feb 5 '13 at 20:33
    
i am trying to do realtime like the tail -f does, how do i make the above show constantly and not just report once –  user157574 Feb 5 '13 at 20:35
    
combining your awk '{ x = $2 " " $4 " " $7 ; printf "%-15s %-20s %4d\n", $1, x, $7}' with my tail -f access_log got me very close, thank you so much –  user157574 Feb 5 '13 at 20:39
    
i am getting the following IP - TIME DATE - PAGE - 0, what does the 0 at the end mean? –  user157574 Feb 5 '13 at 20:41
    
Remove %4d before \n –  Zippyduda Feb 5 '13 at 20:47

Recently, I developed an open-source tool (script) to do what you want, called httpdmon.

It is written in PHP so it is easily customizable (though you're welcome to ask for more features on Github).

Here's a screenshot:

httpdmon in action

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.