10-19-2001
9,926,
461
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,926
Thanks Given: 63
Thanked 461 Times in 270 Posts
Instead of:
ps -ef | grep init | grep -v grep
try this:
ps -ef | grep [i]nit
Here we're giving grep a regular expression that matches "init" but doesn't match itself. So we don't need a second grep process to remove the first. Saves a process.
squash, the ping command comes in several forms. Look at your man page and find out out to ping a host exactly four times then stop. On HP-UX it's "ping host -n 4" and on Sun it's "ping -I 1 host 64 4". I don't know what it will be on your system.
Next, pipe it to "wc -l" and run it against a real host and a non-existant one. See how many lines of output you get in each case. For example, on Sun, I get 3 lines for the bad host and 8 for the good. So now that will be our test.
On the Sun I would do:
WATCH=`ping -I 1 host 64 4 | wc -l`
and check that WATCH was 8 on I would page/send mail. But again, you will need to fiddle with both the ping command syntax and the constant for the test to match stuff to your system.