Please refer this first-To Understand the flow of script.
#!/bin/bash
dt=`date +%r`
logFile="/u01/monitor/batchcheck.log"
cd /u01/monitor/
checkLogResult=`sh check_log -F /u01/java_abc/apache-tomcat-5.5.31/applications/logs/java_abc.log -O /u01/monitor/java_abc.log.old -q "ORA|java.lang.RuntimeException: Couldn't get the connection"`
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] Pattern not found. Controller.log looks [ OK ]\n" >> $logFile
exit 0
else
echo "[ $dt ]Oops! DB Connection error occured..." >> $logFile
echo "$checkLogResult" >> $logFile
echo "Checking db connection.." >> $logFile
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 5 sec..." >> $logFile
sleep 5
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 10 sec..." >> $logFile
sleep 10
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 15 sec..." >> $logFile
sleep 15
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo -ne "We have a serious problem with db...Contact DBA\nSending email notification...\n" >> $logFile
sh /u01/monitor/CriticleEmail.sh
echo -ne "Email notification sent.\n" >> $logFile
exit 1
fi
fi
fi
fi
fi
exit 0
#!/bin/bash
dt=`date +%r`
logFile="/u01/monitor/batchcheck.log"
cd /u01/monitor/
checkLogResult=`sh check_log -F /u01/java_abc/apache-tomcat-5.5.31/applications/logs/java_abc.log -O /u01/monitor/java_abc.log.old -q "ORA|java.lang.RuntimeException: Couldn't get the connection"`
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] Pattern not found. Controller.log looks [ OK ]\n" >> $logFile
exit 0
else
echo "[ $dt ]Oops! DB Connection error occured..." >> $logFile
echo "$checkLogResult" >> $logFile
echo "Checking db connection.." >> $logFile
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 5 sec..." >> $logFile
sleep 5
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 10 sec..." >> $logFile
sleep 10
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo "Retrying in 15 sec..." >> $logFile
sleep 15
ssh oracleuser@DBSERVER 'sh /home/oracle/scripts/dbMonitor'
if [ $? -eq 0 ]
then
echo -ne "[ $dt ] dbCheck says, DB connection looks [ OK ]\n" >> $logFile
echo -ne "Restarting JAVA APPS ...\n" >> $logFile
sh /u01/monitor/java_app_restart
echo -ne "JAVA Apps restarted.You must have received email notification for same.\n" >> $logFile
exit 0
else
echo -ne "[ $dt ] \t dbCheck says, DB connection looks [ NOT OK ]\n" >> $logFile
echo -ne "We have a serious problem with db...Contact DBA\nSending email notification...\n" >> $logFile
sh /u01/monitor/CriticleEmail.sh
echo -ne "Email notification sent.\n" >> $logFile
exit 1
fi
fi
fi
fi
fi
exit 0
No comments:
Post a Comment