shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [shell-script] Access.log


From: MrBiTs
Subject: RE: [shell-script] Access.log
Date: Thu, 28 Jul 2005 09:48:53 -0300

Depois de interpretar o seu e-mail:

O primeiro campo do log é exatamente a data e hora em um formato chamado
Unix Timestamp. Veja mensagens anteriores na lista com uma explanação minha
sobre o que é Unix Timestamp. 

Para converter Unix Timestamp para uma data "legível", você pode usar algo
assim:

$ echo "1121433103" | awk '{print strftime("%F %H:%M:%S",$1),substr($0,
14)}'
2005-07-15 10:11:43 

Usei o formato ANO-MES-DIA HORA:MINUTO:SEGUNDO já pensando num banco de
dados ai. Temos a data em formato ANSI.

Vamos tomar a sua linha de log como exemplo:
1121433103.866   7146 10.0.20.208 TCP_MISS/200 27414 GET
http://www.sysinternals.com/images/screenshots/TcpView.gif gisleine 
DIRECT/66.193.254.46 image/gif

Interessa-nos os campos 1, 3, 7 e 8

Agora, você vai ler o seu arquivo de alto a baixo, mais ou menos assim:

#!/bin/bash

while read LINHA ; do
        set - $LINHA
        AUX=$(echo $1 | cut -d "." -f 1)
        DATA=$(echo $AUX | awk '{print strftime("%F %H:%M:%S",$1)}')
        echo "$DATA $3 $7 $8"
done < access.log

E o seu resultado vai ser algo como:

2005-07-15 10:11:43 10.0.20.208
http://www.sysinternals.com/images/screenshots/TcpView.gif gisleine




------------------------------------------
"There is still more Unix-nature in one
line of shell script than there is in ten
billion lines of C" 
Master Foo - Sh-bng Province - 530 B.C.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]