Wednesday, October 26, 2011

Database Check using Perl and Shell script

I ran into a host that did not support Oracle Grid Control Agent 12c since it is running Red Hat 3 OS so I needed to resort to old shell script for alert.

I use a Perl script so that I can eventually put this into a Oracle User Defined Metric ( UDM ) for Grid Control.

Here is the perl script and the shell script.
The PERL script calls the Shell Script.

#!/usr/local/bin/perl
system ("/home/oracle/script/chkdbup.sh");
$infile="/tmp/dbup.tmp";
open(IN,"$infile") || die "cannot open $infile for reading: $!";
$alert=0; # 0 = down, 1 = up
while ( ) {
if (/PRODB/) {
print "1\n";
$alert=1;
}
}
if ( $alert == 0 ) {
system ("/home/oracle/script/alert.sh");
}
close (IN);

Shell Script

#!/bin/bash
export ORACLE_SID=EMGC
export db=PRODDB
export ORAENV_ASK=NO
. oraenv
$ORACLE_HOME/bin/sqlplus /nolog

<< EOF
set pagesize 0
set echo off
set feedback off
conn dbsnmp/password@$db
spool /tmp/dbup.tmp
select global_name from global_name;
spool off
exit
EOF

No comments:

Post a Comment