Operating System - HP-UX
1832310 Members
2141 Online
110041 Solutions
New Discussion

Need one script to send E-mail.

 
Gulam Mohiuddin
Regular Advisor

Need one script to send E-mail.

I need a simple script to send an E-mail based on some condition. This script I will put in crontab.

I want to check if Oracle database is down, then send E-mail notification to DBA.

For exaple:

IF [ Database is Down] then
echo 'Message' |sendmail gulam@region.on
Endif

We usually check if Oracle is up or down by

$ps -ef|grep pmon

If there is any oracle pmon process running, this command will show its details, so this means Oracle is up otherwise it is down.

But I really don't know how to check this condition.

Thanks,

Gulam.
Everyday Learning.
2 REPLIES 2
Anthony Goonetilleke
Esteemed Contributor

Re: Need one script to send E-mail.

Try something like this..


#!/bin/sh
# Author: Anthony Goonetilleke
# Desc: Monitor Oracle instances
######################################

ORA_INSTANCES=24
CUR_ORA_INSTANCES=`ps -ef | grep -c pmon`
HOST=`/usr/bin/hostname`
MAIL="/usr/bin/mailx"
SUBJECT="Problem on ${HOST}: ${CUR_ORA_INSTANCES} Ora instances available"
RECIPIENTS="youremail@domain.com"

if (( $CUR_ORA_INSTANCES < $ORA_INSTANCES ))
then
echo "You have an Oracle problem" | $MAIL -s"${SUBJECT}" $RECIPIENTS
else
echo "You dont have an Oracle problem" | $MAIL -s"All is well" $RECIPIENTS
fi
Minimum effort maximum output!
federico_3
Honored Contributor

Re: Need one script to send E-mail.


Simply you can do like this:

#!/bin/sh
# check about oracle database

orac_chk=`ps -ef| grep pmon | grep -v grep`

if [ ${#orac_chk} -eq 0 ]
then
echo "oracle is DOWN" | mailx -s ?racle check"gulam@region.on

fi



regards,
federico