ravi
May 2, 2019, 2:05am
1
hi all, here is the sample log file and these errors are repeated in log file..
i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script
<log-message>
<timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<application-id>xxxxx</application-id>
<subsystem-id>INTF</subsystem-id>
<host-name>xxxx</host-name>
<log-origin>PFL</log-origin>
<thread-id>MCulEngine14</thread-id>
<uid>606</uid>
<message>cannot make thumbnail image</message>
<user-id> </user-id>
<additional-info> </additional-info>
</log-message>
Can any one help me on this.
OUTPUT should be on below manner:
<timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>
<timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>
Thanks in Advance,
Hello ravi,
Could you please try following once.
awk -F"[><]" '
/\/log-message/{
if(value){
print value
}
value=""
next
}
/timestamp/{
value="timestamp="$3
next
}
/severity/{
value=value ORS "severioty="$3
next
}
/message/{
value=value ORS "message="$3
}
END{
if(value){
print value
}
}
' Input_file
Thanks,
R. Singh
1 Like
awk '
/ERROR/ {print prev ORS $0; flag=1}
/message/ && flag {print; flag=0}
{prev = $0}
' file > out.log
1 Like
ravi
May 2, 2019, 3:21am
4
ravindersingh13:
Hello ravi,
Could you please try following once.
awk -F"[><]" '
/\/log-message/{
if(value){
print value
}
value=""
next
}
/timestamp/{
value="timestamp="$3
next
}
/severity/{
value=value ORS "severity="$3
next
}
/message/{
value=value ORS "message="$3
}
END{
if(value){
print value
}
}
' Input_file
Thanks,
R. Singh
Hi Singh, Thanks for your help, the above code is giving the out put but i need out put which are related to severity=ERROR and message = cannot make thumbnail image .. these two conditions need to satisfy ..
Thanks.
ravi:
Hi Singh, Thanks for your help, the above code is giving the out put but i need out put which are related to severity=ERROR and message = cannot make thumbnail image .. these two conditions need to satisfy ..
Thanks.
Hello ravi,
2 things here.
1- For thanking any person for any useful post(s) you could HIT thanks button at bottom left corner of each post
2- For your question; you have to provide samples of input and output in correct needed manner on forums, we can't guess that; so please provide in your post with CODE TAGS(see how your first post was edited).
Thanks,
R. Singh
1 Like
ravi
May 2, 2019, 3:31am
6
ravindersingh13:
Hello ravi,
2 things here.
1- For thanking any person for any useful post(s) you could HIT thanks button at bottom left corner of each post
2- For your question; you have to provide samples of input and output in correct needed manner on forums, we can't guess that; so please provide in your post with CODE TAGS(see how your first post was edited).
Thanks,
R. Singh
hi Singh, this first time am using this forum, so am not aware to click that thanks button, because of that i conveyed my greetings in words, going forward i will do HIT thanks button
I have updated my requirement input and output. thanks for your suggestion. Please help me on this.
RudiC
May 2, 2019, 4:16am
7
With your amended spec, try also
grep -E "<(timestamp|severity|message)" file | paste -sd"\t\t\n" | grep -E "ERROR.*thumbnail" | tr '\t' '\n'
2 Likes
ravi
May 2, 2019, 4:36am
8
rudic:
With your amended spec, try also
grep -E "<(timestamp|severity|message)" file | paste -sd"\t\t\n" | grep -E "ERROR.*thumbnail" | tr '\t' '\n'
thanks for your help, its not working and not giving any output.
RudiC
May 2, 2019, 4:40am
9
It has been tested with your input sample:
grep -E "<(timestamp|severity|message)" file | paste -sd"\t\t\n" | grep -E "ERROR.*thumbnail" | tr '\t' '\n'
<timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>
What are your OS and grep
versions?
1 Like
ravi
May 2, 2019, 5:26am
10
rudic:
It has been tested with your input sample:
grep -E "<(timestamp|severity|message)" file | paste -sd"\t\t\n" | grep -E "ERROR.*thumbnail" | tr '\t' '\n'
<timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>
What are your OS and grep
versions?
hi RudiC, my OS is RHEL 7.5, can you please share complete code , i think some where i am missing
RudiC
May 2, 2019, 5:29am
11
That IS the complete code, running with your input sample. Did you replace "file" with your input file name?
1 Like
ravi
May 2, 2019, 5:55am
12
hi RudiC, thanks for your support, issue resolved, need small info what -sd will do in your code..?
RudiC
May 2, 2019, 6:13am
13
man paste
:
-d, --delimiters=LIST
reuse characters from LIST instead of TABs
-s, --serial
paste one file at a time instead of in parallel
HOW did you resolve the issue?
1 Like
gnu version
grep -B1 -A7 "ERROR" file | grep "<timestamp\|<severity\|<message"
ravi
May 13, 2019, 3:28am
15
Hi Rudi, i have made your code in shell script as below
daslog.sh
grep -E "<(timestamp|severity|message)" das.xml | paste -sd"\t\t\n" | grep -E "ERROR" | tr '\t' '\n' >> dasoutput.log
and set up cronjob like
* * * * * /local/flamingo/log/das/daslog.sh >> /local/flamingo/log/das/output.log >> /local/flamingo/log/das/output.log
here the problem is if i run shell script manually it is updating dasoutput.log but through cronjob its not updating dasoutput.log.
can you help me on this.
--- Post updated at 07:28 AM ---
hi all,
i have made below code in shell script as below
daslog.sh
grep -E "<(timestamp|severity|message)" das.xml | paste -sd"\t\t\n" | grep -E "ERROR" | tr '\t' '\n' >> dasoutput.log
and set up cronjob like
/local/flamingo/log/das/daslog.sh >> /local/flamingo/log/das/output.log >> /local/flamingo/log/das/output.log
here the problem is if i run shell script manually it is updating dasoutput.log but through cronjob its not updating dasoutput.log.
can any one help me on this.
RudiC
May 13, 2019, 4:43am
16
That cron
job looks suspect. Do you really want it to trun every minute? Do you really need to redirect stdout twice? Do you receive an error mail?
And, the redirection in daslog.sh
will override the redirection in crontab
. Look for dasoutput.log
in the user's home directory.
1 Like
ravi
May 13, 2019, 5:02am
17
rudic:
That cron
job looks suspect. Do you really want it to trun every minute? Do you really need to redirect stdout twice? Do you receive an error mail?
And, the redirection in daslog.sh
will override the redirection in crontab
. Look for dasoutput.log
in the user's home directory.
no for testing , i made it for every minute and i tried with
/local/flamingo/log/das/daslog.sh > /local/flamingo/log/das/output.log >> /local/flamingo/log/das/output.log this way also but not working.
RudiC
May 13, 2019, 5:20am
18
Please answer ALL questions.
1 Like