sorting log files
- I found in the faq below how to sort log file.
I want to use the shell script below but i don't know how to pass the log
file an have it sorted.
Thank for your help.
16. How can I process multiple logs from a server farm?
Q: I have multiple load-balanced servers (or I'm using DNS round-robin to
accoplish the same thing) and I want to generate one webalizer report for
the whole farm, but each server generates its own log file. When I run
webalizer on each of the logfiles in turn, it ignores a lot of the records
because it thinks they're out of order!
A: You need to merge all of the logfiles together so that webalizer sees the
records in chronological order. One good way to do that on the fly is with
mergelog ( http://mergelog.sourceforge.net/) , a quick common logfile
sorter. An example:
mergelog .log .log .log | webalizer
Another method is to simply combine your logs and then sort them into
chronological order. Here is a simple shell script that uses the GNU sort
utility to sort an already combined log file:
if [ ! -f $1 ]; then
echo "Usage: $0 "
echo "Sorting $1"
sort -t ' ' -k 4.9,4.12n -k 4.5,4.7M -k 4.2,4.3n -k 4.14,4.15n -k 4.17,4.18n
-k 4.20,4.21n $1 > $1.sorted
Chat with friends online, try MSN Messenger: http://messenger.msn.com