LDAP ログ ファイルから特定のユーザーのバインドを「grep」しようとしています。必要な行は、ログ内の複数の行に分散されます。入力例は次のとおりです。
[2009/04/28 17:04:42.414] DoBind on connection 0x7c8affc0
[2009/04/28 17:04:42.414] Bind name:cn=admin,ou=appids,o=admineq, version:3, authentication:simple
[2009/04/28 17:04:42.415] Failed to authenticate local on connection 0x6cc8ee80, err = log account expired (-220)
[2009/04/28 17:04:42.416] Sending operation result 53:"":"NDS error: log account expired (-220)" to connection 0x6cc8ee80
[2009/04/28 17:04:42.416] Operation 0x3:0x60 on connection 0x6cc8ee80 completed in 3 seconds
[2009/04/28 17:04:42.416] Sending operation result 0:"":"" to connection 0x7c8affc0
[2009/04/28 17:04:42.416] Operation 0x1:0x60 on connection 0x7c8affc0 completed in 0 seconds
[2009/04/28 17:04:48.772] DoSearch on connection 0x7c8affc0
[2009/04/28 17:04:48.772] Search request:
base: "o=intranet"
scope:2 dereference:0 sizelimit:0 timelimit:600 attrsonly:0
filter: "(guid='03ADmin)"
attribute: "cn"
attribute: "cn"
attribute: "cn"
attribute: "cn"
attribute: "objectClass"
attribute: "guid"
attribute: "mail"
[2009/04/28 17:04:48.773] Sending operation result 0:"":"" to connection 0x7c8affc0
[2009/04/28 17:04:48.773] Operation 0xe851:0x63 on connection 0x7c8affc0 completed in 0 seconds
この例では、結果は次のようになります。
[2009/04/28 17:04:42.414] DoBind on connection 0x7c8affc0
[2009/04/28 17:04:42.414] Bind name:cn=admin,ou=appids,o=admineq, version:3, authentication:simple
[2009/04/28 17:04:42.416] Sending operation result 0:"":"" to connection 0x7c8affc0
[2009/04/28 17:04:42.416] Operation 0x1:0x60 on connection 0x7c8affc0 completed in 0 seconds
基本的に、これは複数の接続にわたるサーバー操作のログです。管理ユーザーによる「バインド」操作に費やされた時間を分析する必要がありますが、このサーバーは非常にビジーであるため、多くのノイズを除去する必要があります。
擬似コード:
for each line in file
if line contains "DoBind" and next line contains "cn=admin"
print both lines
find the connection number X in lines
skip lines until "Sending operation result.*to connection X" is found
print two lines
この例では、ユーザー「cn=admin」が前にある「DoBind」行と、接続番号「0x7c8affc0」に従ってリストされている結果行を取得したいと思います。別の接続で行われている「認証に失敗しました」メッセージなど、バインドの開始と終了の間で必要のない他の操作が行われる場合があります。
さらに、バインドが完了した後、接続で他の操作が行われますが、これには興味がありません。上記では、「バインド」後に発生した DoSearch 操作の結果をキャプチャしてはなりません。
私は「sed」でこれをやろうとしていますが、これは仕事に適したツールのようです。残念ながら、私は初心者であり、これは学習経験です。これが私がこれまでに持っているものです:
/.*DoBind on connection \(0x[0-9a-f]*\)\n.*Bind name:cn=OblixAppId.*/ p
/.*Sending operation result.*to connection \1\nOperation.*on connection \1 completed.*/ p
sed は、'\1' を使用している 2 行目に文句を言います。接続アドレスをキャプチャし、その後の検索でそれを使用して結果文字列をキャプチャしようとしていますが、明らかに正しく使用していません。「#」変数は、各検索操作に対してローカルであるようです。
ある検索から別の検索に「変数」を渡す方法はありますか、それとも代わりに perl を学習する必要がありますか?