Cron script to check to see if Oracle is up

I need to create a scrip to run in cron to check to see if the oracle database and listener are up - if up do nothing and if not up to mail me a message.
Thanks
LVL 1
bkreynolds48Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gheistCommented:
Did you buy it to enjoy crashes ???
Have you ever patched TNS listener ...???
bkreynolds48Author Commented:
I am looking for a serious answer
gheistCommented:
lstnrctl status >/dev/null 2>&1 < /dev/null
echo $?
bkreynolds48Author Commented:
I know how to check the status of the oracle database and the listener -the question is:

How to create a SCRIPT to run in cron
to
1.) check to see if the oracle DATABASE and  LISTENER are up and running
2.) -- IF they are running then do nothing
3.) ----- IF they are not MAIL me a message.
gheistCommented:
#!/bin/ksh
export ORAHOME=/opt/oracle
/opt/ora/tnsctrl status 2>&1 >>/dev/null < /dev/null
if [$? != 0 ] ; then
MAILDATA=TNS Listener on `hostname` \n fell asleep.
fi
# ... same checks for all databases ( no output and no input with  2>&1 >>/dev/null < /dev/null at the end )

if ...
MAILDATA=Database xyz fell asleep \n $MAILDATA
fi

# and so on and so on

if [ X$MAILDATA !=X ] ; then
/usr/bin/mail -s "Servers sleep so you wake" you@home.dom << EOF
$MAILDATA
EOF

exit 0

# ... exit 0 so the cron does not complain in its logs.

this assumes you can send mail out

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.