Hi - How many job.history file are there regularly ?
- Are they changing over the time ? If yes, how frequently ?
- Are you running this check periodically ? If yes, how frequently ?
I asked these because I am thinking about asking find to consider only files newer than a certain age. Not sure if this can bring any improvement, just thinking. - Is that text you quoted above a single line ?
I ask because a big simplification would be to use a single find and grep for all "FAIL\|ABOR\|whatever" in once. The -o switch would solve to get only the matched word, but sadly if there are multiple matches in a line, it outputs them all, even if -m is specified. Or at least GNU grep does. If your grep has different behavior ( I mean echo 'foo foo' | grep -o -m 1 'foo' ( with or without the -m option ) outputs a single "foo" ) then tell us. But this would not be an issue if there would be no more than one matching word in a line, so this would work : CODEfind /data/SpoolIn -name job.history | xargs grep -o -m 1 -h 'FAIL\|ABOR' | sort | uniq -c This will output a list like : CODE --> output 2 ABOR 3 FAIL Similar thing could be achieved using Sed too : CODEfind /data/SpoolIn -name job.history | xargs sed -n '/FAIL\|ABOR/s/.*\(FAIL\|ABOR\).*/\1/p' | sort | uniq -c Quote (Feherke):And after all, what is your ultimate goal ? Just 4 shell variables, each with the count of a status ?
I asked that because as you can see, a simple list can be output easier, but if you definitely need separate shell variables, Awk would work better : CODEeval $(find /data/SpoolIn -name job.history | xargs awk 'FNR==1{f=0}!f&&match($0,/FAIL|ABOR/){s[substr($0,RSTART,RLENGTH)]++;f=1}END{for(i in s)printf"chk_1%s=%d\n[i]",i,s}') This will create shell variables like chk_1ABOR=2 and chk_1FAIL=3. Feherke. http://feherke.github.com/ |
|