linux - Need some help on shell scipt (using grep command) -


i have log file , trying write shell script find multiple strings in file on multiple lines.

for example if see phrases "class=com.comcast.parker.getcurrentaudiolanguageresponse" , "status:ok" in logs, should print getaudiolanguage successful else getaudiolanguage failed. shell script goes this:

scriptfile:

logfile=$1  if grep "{\"class\":\"com.comcast.parker.getcurrentaudiolanguageresponse\"" jags.txt | grep "{\"status\":\"ok\"" | wc -l ;     echo "getaudiolanguage successful" fi if grep "{\"class\":\"com.comcast.parker.getcurrentaudiolanguageresponse\"" $logfile | grep -q "general_error" | wc -l ;     echo "getaudiolanguage failed" fi 

in logs, status general_error, should print failed, output shows getaudiolanguage successful ..

any regarding this?

logfile:

160125-11:11:28.442500 [mod=sys, lvl=info] [tid=2332] ======= message onrpccall ======> 160125-11:11:28.442614 [mod=sys, lvl=info] [tid=2332] entering onrpccallevent request ---> getaudiolanguage 160125-11:11:28.442845 [mod=sys, lvl=info] [tid=2332] received json request = {"event":1,"handler":1,"name":"onrpccall","params":{"callguid":"d75a5bab-6b29-4ab4-9f7e-3cf32d4a05b1","callparams":[{"getaudiolanguage":{}}],"class":"com.comcast.xre.events.xrerpccallinfo","destinationsessionguid":"ab00ebea-5f63-4619-9877-273a2bceea1d","method":"getaudiolanguage","sourcesessionguid":"ab00ebea-5f63-4619-9877-273a2bceea1d"},"phase":"standard","source":1}  160125-11:11:28.442920 [mod=sys, lvl=info] [tid=2332] getcurrentaudiolanguage : entered 160125-11:11:28.442968 [mod=sys, lvl=info] [tid=2332] pmainplayer null. 160125-11:11:28.443012 [mod=sys, lvl=info] [tid=2332] getaudiolanguage: audio language returned ��v`>       t�=     t0~�t 160125-11:11:28.443676 [mod=sys, lvl=info] [tid=2332] ====== response sending {"appid":1,"command":"call","commandindex":5,"method":"generateappevent","params":[{"class":"com.comcast.xre.events.xreoutgoingevent","name":"onrpcreturn","params":{"callguid":"d75a5bab-6b29-4ab4-9f7e-3cf32d4a05b1","class":"com.comcast.xre.events.xrerpcreturninfo","destinationsessionguid":"ab00ebea-5f63-4619-9877-273a2bceea1d","method":"getaudiolanguage","returnval":{"class":"com.comcast.parker.getcurrentaudiolanguageresponse","status":"general_error","statusmessage":"getting current audio language unsuccessful."},"sourcesessionguid":"ab00ebea-5f63-4619-9877-273a2bceea1d"}},"ab00ebea-5f63-4619-9877-273a2bceea1d"],"targetid":1,"targetpath":"","timestamp":0} 

rather multiple grep can use single awk this:

awk '/{"class":"com\.comcast\.parker\.getcurrentaudiolanguageresponse"/{    exit ($0 !~ /"status":"general_error"/)}' file && echo "getaudiolanguage failed"  awk '/{"class":"com\.comcast\.parker\.getcurrentaudiolanguageresponse"/{    exit ($0 !~ /"status":"ok"/)}' file && echo "getaudiolanguage successful" 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -