Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export Oracle diagram from Oracle DB including VIEWS 8 105
data lookup in Oracle - need suggestions 55 104
Export table into csv file in oracle 10 47
selective queries 7 22
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

895 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

14 Experts available now in Live!

Get 1:1 Help Now