Solved

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

Posted on 2010-09-16
5
2,305 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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 shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

777 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