データベースログ用のシェルスクリプト

データベースログ用のシェルスクリプト

実際のログファイルは次のとおりです。

$ 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
.
.
.

総ライン数は約20,000本です。このログファイルには、次の一意のエラーが表示されます。

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

以下は結果セットです。一定ではなく変更されます。

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

各エラーのプロセスID(pid)を取得するには、以下を使用しました。

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

これでプロセスIDを取得したので、そのプロセスIDの完全な情報を取得する必要があります。

$ 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?   

3つのfindコマンドをすべてシェルスクリプトに入れてプロセスを自動化するにはどうすればよいですか?エラーと行数はさまざまです。何も同じままではありません。

ベストアンサー1

おすすめ記事