Computing.Net > Forums > Unix > Unix Script Error, Quel Strange

Unix Script Error, Quel Strange

Reply to Message Icon

Original Message
Name: Diplomat365
Date: July 2, 2003 at 01:46:31 Pacific
Subject: Unix Script Error, Quel Strange
OS: SunOS 5.7
CPU/Ram: 4 CPU / 4GB
Comment:

I've written a unix script that monitors unix processes on a server. If the number of processes running drops below an expected level in mails a support box. Simple enough you may think and indead it is...

However, if a I name this shell script as bvwatchermon it gives a weird over counting fault. I expect it to find 2 processes and reports either 3 or 4. I if I rename the script to marty.sh for example it returns the expected 2 processes every time.

Any ideas, just curuious really as I don't see why there should be a fault.



Report Offensive Message For Removal

Response Number 1
Name: Don Arnett
Date: July 2, 2003 at 08:27:50 Pacific
Subject: Unix Script Error, Quel Strange
Reply: (edit)

I'll bet that the name of what you are watching is included in the name "bvwatchermon" and that you are using a 'grep' to pull the processes out of a 'ps' list.

For example, if you are looking for processes named 'bv', you might do something like:

ps -ef | grep bv | wc -l

But, in the list returned by 'ps' will be the 'bvwatchermon' script (which will match) and also the 'grep bv' (which will match).

Although if this is the problem, you'd still have the 'grep' process regardless of the watcher shell name.

Anywho, the way I get around this is something like:

ps -ef | grep "bv" | grep -v "bvwatchermon" | grep -v "grep" | wc -l


The -v on the second and third grep exclude the lines with 'bvwatchermon' and 'grep' from the counted list.



Report Offensive Follow Up For Removal

Response Number 2
Name: diplomat365
Date: July 3, 2003 at 01:37:37 Pacific
Subject: Unix Script Error, Quel Strange
Reply: (edit)

Thanks that is indeed it, took 3 of us not to notice that thanks.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Unix Script Error, Quel Strange

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software