Scripts shell para os logs do banco de dados

2

O arquivo de log real será assim

$ cat file1.log
time=2014-07-23 23:56:28 GMT, user=[unknown], db=[unknown], host= pid=28254 LOG: 
time=2014-07-23 23:56:28 GMT, user=portalman, db=ss, host=172.18.183.45 pid=28254 LOG:  connection authorized: user=portalman database=ss
time=2014-07-23 23:57:28 GMT, user=[unknown], db=[unknown], host= pid=28269 LOG:  connection received: host=172.18.183.45 port=14493
time=2014-07-23 23:57:28 GMT, user=portalman, db=ss, host=172.18.183.45 pid=28269 LOG:  connection authorized: user=portalman database=ss
time=2014-07-23 23:57:28 GMT, user=[unknown], db=[unknown], host= pid=28270 LOG:  connection received: host=172.18.183.45 port=14494
time=2014-07-23 23:57:28 GMT, user=portalman, db=ss, host=172.18.183.45 pid=28270 LOG:  connection authorized: user=portalman database=ss
time=2014-07-23 23:57:58 GMT, user=[unknown], db=[unknown], host= pid=28273 LOG:  connection received: host=172.18.183.45 port=14495                                            
column "actice" does not exist at character 17
.
.
.

O total de linhas será de cerca de 20.000. Neste arquivo de log eu preciso buscar os erros únicos, que eu tenho através deste comando:

$ find file1.log | xargs grep -e ERROR -e FATAL | cut -d ":" -f4,5 |sort |uniq

A seguir está o conjunto de resultados e não constante, varia

syntax error at or near "?" at character 1
syntax error at or near "[" at character 1
syntax error at or near "desc" at character 1
syntax error at or near "describtion" at character 1

Para obter o id do processo (pid) de cada erro que usei:

$ find file1.log | xargs grep 'syntax error at or near "?" at character 1' | cut -d " " -f8 | tail -1
pid=25997

Agora eu tenho o id do processo, então eu preciso buscar toda a informação desse id processo

$ find file1.log  | xargs grep pid=25997
time=2014-07-23 23:10:02 GMT, user=[unknown], db=[unknown], host= pid=25997 LOG:  connection received: host=[local]
time=2014-07-23 23:10:02 GMT, user=dbman, db=ss, host=[local] pid=25997 LOG:  connection authorized: user=dbman database=ss
time=2014-07-23 23:10:02 GMT, user=dbman, db=ss, host=[local] pid=25997 ERROR:  syntax error at or near "?" at character 1
time=2014-07-23 23:10:02 GMT, user=dbman, db=ss, host=[local] pid=25997 STATEMENT:  ?column?   

Como colocar todos os 3 comandos find em um shell script & fazer o processo automaticamente? Os erros & número de linhas varia. Nada é constante.

    
por user3359124 24.07.2014 / 15:49

0 respostas