shell - How to grep http request and response for specific MSISDN in logs -


i want grep http request , response log file , use following criteria

  • first grep msisdn in logs

    less service.log

    check pattern /msisdn 1234567 above commands give me place received request in logs

  • then id of http request logs
  • on base of id response of request

above steps done on 1 file available in 1 file.

now want automate above steps, use following commands

sample request , response following present in 1 file

id: 10814276 address: http://1.1.1.1:80/myws?wsdl encoding: utf-8 http-method: post content-type: text/xml; charset=utf-8 headers: {accept=[application/soap+xml, application/dime, multipart/related, text/*],                      cache-control=[no-cache], content-length=[1363], content-type=[text/xml; charset=utf-8],     host=[x.x.x.x:80], p ragma=[no-cache], soapaction=["cancel"], user-agent=[axis/1.4], x-forwarded-for=[1.1.1.1]} payload: <?xml version="1.0" encoding="utf-8"?><soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"><soapenv:header> </soapenv:header> <soapenv:body> <cancel ><msisdn>12345678</msisdn><transactionid>955316475</transactionid>     </cancel> </soapenv:body> </soapenv:envelope> 

following response

id: 10814276 encoding: utf-8 content-type: text/xml headers: {nmrmessage=[message []]} payload: <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">    <soap:body><cancelresponse><responsecode>4020100</responsecode><description>exception:     {java.lang.linkageerror: com/sun/xml/messaging/saaj/soap/ver1_1/fault1_1impl}</description>    <status>1</status><actioncode xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:nil="true"/><inactivationdate xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:nil="true"/></cancelresponse></soap:body></soap:envelope> 

try this:

lookup_id() {     local id     id="$1"     grep -e ^id: -e '<msisdn>' service.log | awk '     begin { rs="id: "; fs="\n" }      {          if ($2) {             sub(/.*<msisdn>*/, "", $2)            sub(/<\/msisdn>.*/, "", $2)            print $2 " " $1          }      }' > msisdn_to_id     lookup=$(grep $id msisdn_to_id | awk '{ print $2 }')     awk 'begin { rs="id: "; ors "\n" }      $1 == '$lookup' && !match($2, /^address/)  {          print "id: " $0      }' service.log     rm msisdn_to_id }  lookup_id 12345678 

i've tried keep posix-compliant run on solaris, written on ubuntu , work may needed (particularly on awk parts)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -