Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2674
  • Last Modified:

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

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
orcun_turkec
Asked:
orcun_turkec
  • 2
  • 2
3 Solutions
 
BigbojCommented:
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
 
slightwv (䄆 Netminder) Commented:
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
 
orcun_turkecAuthor Commented:
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
 
slightwv (䄆 Netminder) Commented:
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
 
orcun_turkecAuthor Commented:
Thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now