Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect Logfile Format to be Analysed

Status
Not open for further replies.

Dronealone

IS-IT--Management
Mar 13, 2002
64
GB
Hello,

I am runnign Linux/Apache and used rotatelogs to rotate my logs! Unfortunately I changed the format of the logfiles to the following:

217.2.38.18 217.2.38.18 [16/Feb/2002:13:52:16 +0000] "GET /login.php HTTP/1.1" 200 14659 "eting/dldetail.php?id=49" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; QXW0339d; Q312461)"

As you can see, the IP address is in their twice. When I try to run Webtrends/HTTP-Analyse over it, they cannot read the log file.

I have a client who desperately wants their monthly report and I can't give it to them! Does anyone know how I can get these logs to be analysed???

Thanks very much!
 
Unless there is an easier way, this is what I'd do

Export it to Excel, delete the duplicate column and then save again as a logfile.
 
Hi,

Try this python code I just wrote :

#! /usr/bin/env python

import string
import sys

if __name__ == "__main__":
if len(sys.argv) > 1:
try:
fin = open(sys.argv[1], "rb")
except:
print 'Cannot open : ' + sys.argv[1]
sys.exit(1)
fout = open(sys.argv[1]+'.copy', "wb")
while 1:
t = fin.readline()
if t == '':
break
s = string.split(t,' ',1)
fout.write(s[1] + '\r')
fin.close()
fout.close()
print 'copy finished'


Just save it as /root/logzap.py or something then do :

# cd /var/log/httpd
# /root/logzap.py access_log.1 (etc.)

It should strip off the first IP address and make an oterwise identical file with the suffix of .copy

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top