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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix Script Error, Quel Strange

Reply to Message Icon

Name: Diplomat365
Date: July 2, 2003 at 01:46:31 Pacific
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.




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: July 2, 2003 at 08:27:50 Pacific
Reply:

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.



0

Response Number 2
Name: diplomat365
Date: July 3, 2003 at 01:37:37 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix Script Error, Quel Strange

help redoing unix script student db www.computing.net/answers/unix/help-redoing-unix-script-student-db/5151.html

basic unix scripting help www.computing.net/answers/unix/basic-unix-scripting-help/7686.html

Unix Script ignoring cmd line vars www.computing.net/answers/unix/unix-script-ignoring-cmd-line-vars/6193.html