Solved

Windows batch script to check  if an oracle database and listener  is up

Posted on 2010-09-16
5
2,232 Views
Last Modified: 2012-05-10
Hi experts,
I' m using windows 2008 server, I need  two DOS batch scripts  to check if an oracle database and listener  is up  and  to send an  e-mail alert which includes computer name, date/time and a message that DB  or Listener is down.  
0
Comment
Question by:orcun_turkec
  • 2
  • 2
5 Comments
 
LVL 3

Assisted Solution

by:Bigboj
Bigboj earned 125 total points
ID: 33689601
To check if oracle is up:

@echo off
qprocess oracle.exe
if not ERRORLEVEL 0 goto :oracle_down
qprocess tnslsnr.exe
if not ERRORLEVEL 0 goto :listener_down

set MESS=Oracle is up and listening
goto mail

:oracle_down
set MESS=oracle.exe not running
goto mail

:listener_down
set MESS=tnslsnr.exe not running
goto mail

:mail
echo %MESS%
rem Since Windows is not able to send a mail from command line, You
rem have to solve it by Yourself.
rem I personally use Blat:
rem http://sourceforge.net/projects/blat/files/
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 375 total points
ID: 33691132
You will need to add one more step:  The only way to guarantee Oracle is working properly is to connect to it using sql*plus.

Oracle.exe can be running and the database can be down.
0
 

Author Comment

by:orcun_turkec
ID: 33691909
How can this be applied to a batch script   Slightwv ?

As Bigboj said, I wrote a batch script  as shown below ;

@echo off
qprocess oracle.exe
if not  ERRORLEVEL 0 goto :oracle_down
:oracle_down
set MESS=%COMPUTERNAME% oracle.exe not  running
goto mail
:mail
echo %MESS%


How can the sqlplus command ( sqlplus sys/xxxx as sysdba )  can be applied to this script?
And what are other tools or scripts except Blat application for sending mail ?
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 375 total points
ID: 33692337
Try the following code for sqlplus

for mail maybe a VBS script:
http://www.petri.co.il/send_mail_from_script.htm

or powershell:
http://weblogs.asp.net/steveschofield/archive/2008/01/09/send-email-with-powershell-script-schedule-script-with-windows-task-scheduler.aspx
@echo off

(

echo username/password

echo whenever sqlerror exit failure

echo select 'Works' from dual;

) | sqlplus -s



echo %ERRORLEVEL%

Open in new window

0
 

Author Comment

by:orcun_turkec
ID: 33715752
Thank you
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now