Script that watches an apache log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that watches an apache log file
# 1  
Old 11-19-2014
Script that watches an apache log file

i'm trying to write a basic script that "watches" the apache access.log file and prints out lines that correspond to slow requests, Im checking for how microseconds it's taken. For the sake of testing, i'm using any number field.

so far I have:-
Code:
watch --interval=1 "tail access.log | cut -d ' ' -f2 "

that command will output the following e.g.
Code:
523
2334
22234
222
2234

I want to test each f2 field if it's greater than or less than a certain value I only want to output that field and ignore the rest, this is where I need help with, any feedback will be greatly appreciated.

thanks


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 11-19-2014 at 05:39 AM..
# 2  
Old 11-19-2014
You should be able to run this without the watch:

Code:
tail -f access.log | awk '$2 >= MIN { print $2 }' MIN=1000 -

awk is like grep on steroids, with actual expressions and comparisons and if-then and columns. You find it on any UNIX system.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-19-2014
that's brilliant! thank you

now I have all those numbers I need saved in variable A, I want to add all those numbers up I want to show show (1) the average and (2) the maximum value, I'm getting stuck getting an average value

Code:
for i in $A; do
           echo item: $i
$sum=$sum+$i;
$i>=$maxValue
        done
echo $sum
echo $max

# 4  
Old 11-19-2014
Code:
N=0
AVG=0
for I in $A
do
       let AVG=AVG+I
       let N=N+1
done

[ $N -gt 0 ] && let TOTAL=AVG/N

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parse apache log file with three different time formats

Hi, I want to parse below file and Write a function to extract the logs between two given timestamp. Apache (Unix) Log Samples - MonitorWare The challenge here is there are three date and time format. First :- 07/Mar/2004:16:05:49 Second :- Sun Mar 7 16:02:00 2004 Third :- 29-Mar... (6 Replies)
Discussion started by: sahil_shine
6 Replies

2. Red Hat

Apache log rotate configuration

HI i was trying to configure logrotate for my apache server and it's not working properly. Os: Red Hat 6 here is my lodrotate configuration /var/log/httpd/*log { daily missingok notifempty sharedscripts compress delaycompress postrotate ... (3 Replies)
Discussion started by: bentech4u
3 Replies

3. Shell Programming and Scripting

Bash script to copy apache log files to client directory

Our Apache log files are written to a location on the server that we as clients have no access. Don't ask. Every month, I have to e-mail the administrator to have him manually copy our Apache log files to a directory in our file space. You can probably guess how efficient it is to do things this... (3 Replies)
Discussion started by: gregraven
3 Replies

4. HP-UX

Script to monitor /var/opt/resmon/log/event.log file

AM in need of some plugin/script that can monitor HP-UX file "/var/opt/resmon/log/event.log" . Have written a scrip in sh shell that is working fine for syslog.log and mail.log as having standard format, have interrogated that to Nagios and is working as I required . But same script failed to... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

5. Shell Programming and Scripting

Apache log file pharsing, need help!!!!

I`m new to shell scripting and I need some help here I`m trying to pharse Apache log and I encountered a problem so I need some help... How to break line into fields having different field separators? let`s say I want to break line into 9 fields and the lines format is: text1 text2... (2 Replies)
Discussion started by: Armisan
2 Replies

6. HP-UX

how to use .gdbinit to set watches in WDB

I use wdb for debugging and I like to use its watches functionality to watch the values of variables as i step through the code. Can I set this up in .gdbinit so I don't have to add the variables to my watch list every time i re-run wdb? Thank you very much, Alex (0 Replies)
Discussion started by: rocco50
0 Replies
Login or Register to Ask a Question