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

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

Re: [shell-script] filtrar linha de Log


From: Thobias Salazar Trevisan
Subject: Re: [shell-script] filtrar linha de Log
Date: Mon, 26 May 2003 10:54:53 -0300 (BRT)

ae adriano,

On Mon, 26 May 2003, Adriano da Silva Múfalo wrote:

> Pessoal, olhem este log:
> May 26 10:15:43 webserver ipop3d[6688]: Logout user=usuario host=host
> [192.168.1.10] nmsgs=X ndele=Y
>
> Segue sempre este padrão... (é o log do sendmail)
> Eu gostaria de identificar todas as linhas onde Y > X.

este script deve resolver.

$ cat test.sh
#!/bin/bash

while read l;do
N=$(echo "$l" | sed 's/.*nmsgs=\([0-9]*\) *ndele=\([0-9]*\)/\1 \2/')
[ ${N#* } -gt ${N% *} ] && echo "$l"
done < lixo
########################################

um while pra ler o seu arquivo. Então pegamos linha por linha os
campos que você quer, ou seja, o X e Y. olhe:

$ echo "May 26 10:15:43 webserver ipop3d[6688]: Logout user=usuario
host=host [192.168.1.10] nmsgs=10 ndele=20" |
sed 's/.*nmsgs=\([0-9]\+\) *ndele=\([0-9]\+\)/\1 \2/'
10 20

Colocamos este resultado em uma variável (N) e testamos se Y > X.
Então N, neste caso, vai ter '10 20'

$ echo $N
10 20
$ echo ${N% *}
10
$ echo ${N#* }
20

$ [ ${N#* } -gt ${N% *} ] && echo maior
maior


falow

thobias
-------
echo 9446046325380026818553633794429812592304650P | dc
-------
http://www.lcp.coppe.ufrj.br/~thobias

____________________________
|
| Against - HTML Mail
| Against - MS ATTACHMENTS
|
----------------------------



reply via email to

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