process pager - by cell phone or just e-mail notify

hi all..

i need any help. i want to create in my crontab a simple script for verify any process and notify for the status in my e-mail or cell phone.

anybody help me?

what do you mean when you say 'verify any proccess'??

I suppose in your script you need to include the following commands:
<pre>

ps -ef |grep whatever
grep whatever
mail or any other mailer // for notify youe email.

</pre>

tks Guest100...

when i say "verify process" i talk about verify what process is running, example, i need my server send a notify when the process is down.

understand?

WATCH=`ps -ef|grep whatever|wc -l`

if [[ $WATCH -ne 0 ]]; then
exit 0
else
echo "Process is not running"|mailx -s"SUBJECT HERE" user@blah.com

ok. thanks Optimus_P.

But now, i want my script check the internet conection.
What's the sintax for the correct WATCH with "ping any.address.com"?

If anybody want's help-me, i wait for contact.

Remember! When you ps -ef and pipe to grep, you must filter out the grep with the -v flag.

Ok, Tks Neo, but i want execute a "ping any.address.com"..
If ping not response, i'll notify by e-mail. If the ping response, nothing e-mail is sent.

Can you help-me?

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.

ok, tks.. :slight_smile: now it's working..

I love this guy!