Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One grep, multiple arguments and variables ? 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

another problem.

I'm using the following command to monitor the states of print jobs:

Code:
chk1=$(find /data/ -name job.history -exec grep -l FAILED {}\; | wc -l)
chk2=$(find /data/ -name job.history -exec grep -l WAITING {}\; | wc -l)
chk3=$(find /data/ -name job.history -exec grep -l ABORTED {}\; | wc -l)

The Output of each grep is stored in a variable. As soon as the variable's value becomes greater than 0 there's a message being displayed on my monitoring box saying "Some jobs have failed" or "Some jobs have been aborted" and so on ...

However because there's an enormous directory structure existing under /data/ each find-grep combination takes a significant amount of time to complete.

Now the question is: Is there any way to get rid of 2 of the 3 find-grep commands and accomplish the same goal using only 1 find-grep ?

Regards
Thomas
 
Hi

I would use this :
Code:
find /data/ -name job.history -exec grep -o 'FAILED\|WAITING\|ABORTED' {} \; | sort | uniq -c > /tmp/printjobstatussummary
To produce a temporary file containing information like this :
Code:
      4 ABORTED
      1 FAILED
Producing that temporary file should be abit faster and generating alerts from its content should be fairly simple.

Tested with GNU [tt]grep[/tt]. See if your [tt]grep[/tt] implementation supports the -o ( --only-matching ) switch.

Feherke.
 
Hi feherke,

thanks a lot !
That's perfect !

However: There was no -o option for grep under AIX. But here the "egrep" command did the trick.

Regards
Thomas
 
or grep -E (egrep is deprecated, but still exists in AIX)


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top