Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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.

![]() |
![]() |
![]() |

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