Operating System - HP-UX
1753862 Members
7450 Online
108809 Solutions
New Discussion юеВ

script for the error logs from multiple directories

 
SOLVED
Go to solution
Grayh
Trusted Contributor

script for the error logs from multiple directories

I have the following directories under the dir /var/MS/YER

ROW21_M2_HP1_20080809.163321_FTS_101/
ROW23_M2_HP1_20080809.164402_FTS_101/
ROW24_M2_HP1_20080809.165257_FTS_101/
ROW28_NO_HP1_20080809.171014_FTS_101/
ROW02_NO_HP1_20080809.171249_FTS_101/
ROW03_NO_HP1_20080809.172207_FTS_101/
ROW05_NO_HP1_20080809.173117_FTS_101/
ROW06_NO_HP1_20080809.173942_FTS_101/
ROW09_NO_HP1_20080809.174756_FTS_101/
ROW12_NO_HP1_20080809.175616_FTS_101/
ROW15_NO_HP1_20080809.180438_FTS_101/

I have a .log file in each of the directories above..

Is there a way or script by which I can grep for the string "failed" & the no. of failures(count) from all of the logs in the directories.

plz help
4 REPLIES 4
Tingli
Esteemed Contributor
Solution

Re: script for the error logs from multiple directories

grep failed /var/MS/YER/ROW*101/*.log | wc -l
James R. Ferguson
Acclaimed Contributor

Re: script for the error logs from multiple directories

Hi:

If you want the actual matching lines along with a count of the lines matched at the end, you could use:

# cat ./filter
#!/usr/bin/sh
LOG=/tmp/$(basename $0).$$
trap 'rm ${LOG}' EXIT
grep failed /var/MS/YER/ROW*101/*.log > ${LOG}
cat ${LOG}
wc -l < ${LOG}
exit

...run as:

# ./filter

By the way, please evaulate the answers you received to your previous post, too :-)

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1324828

Regards!

...JRF...
Grayh
Trusted Contributor

Re: script for the error logs from multiple directories

Thanks JRF,

I am about to run this script now... I have a small doubt...

what does the following line do in the script

trap 'rm ${LOG}' EXIT
James R. Ferguson
Acclaimed Contributor

Re: script for the error logs from multiple directories

Hi (again):

> what does the following line do in the script

trap 'rm ${LOG}' EXIT

This simply removes the file named by ${LOG} when the script exits. It's a convenient way to perform simple cleanup code, automatically, without explicitly calling a function or in-lining code, from any point in your script, when it exits.

Regards!

...JRF...