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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GREP question 1

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Good morning

I am writing a script to check that various applications are running. One application needs three component processes to be running can I use grep to check that all three are running and use the exit status to indicate success or failure?

Using grep -e proc1 | proc2 | proc3 will only show if at least one process is running.

Any ideas?

Thanks

Alan
 
Alan, perhaps put the grep in a loop and write the exit status of each iteration to an incrementing variable. If your variable is > 0 at the end, you know one or more of the processes is having a problem. You could probably refine this to identify which, if necessary.

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
Something like this ?
[ `ps -e | grep -cE 'proc1|proc2|proc3'` -eq 3 ] && echo OK

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top