Linux Shell Script Questions and Answers #4

Script for checking status of databases in a server

#######################################################################
#
# Usage : ./check_db.sh
#
# Script for checking status of databases in a server
#
#########################################################################

for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"|cut -d"_" -f3`
do
export ORACLE_SID=$i
sqlplus -s /nolog <<EOF >/tmp/temp.sql
set head off echo off
conn / as sysdba
select decode(open_mode,'READ WRITE','OPEN','MOUNT') from v\$database;
exit
EOF
for x in `cat /tmp/temp.sql |egrep "OPEN|MOUNT|ORA-01507"|grep -v "^sel"|awk {'print $1}'`
do 
if [ "$x" = "ORA-01507:" ]
   then 
echo "Database $i in NOMOUNT stage"
else
echo  "Database $i in $x stage"
fi
done
rm /tmp/temp.sql
done

OUTPUT :

[oracle@sss-oracle ~]$ ps -ef|grep pmon
oracle    6061           1  0 16:10 ?          00:00:00 ora_pmon_sss
oracle   16682          1  0  21:04 ?         00:00:00 ora_pmon_sakthi
oracle   16758    7821   0 21:05 pts/1    00:00:00 grep pmon

[oracle@sss-oracle ~]$ ./check_db.sh
Database sss in OPEN stage
Database sakthi in NOMOUNT stage
 

Check startup and shutdown messages from the alert log.

diff  alert_test.log alert_test.bkp |egrep  "immediate|normal|abort|transactional|Starting ORACLE instance"|egrep -i "Shut|Start" > /tmp/DBDown.log
x=`diff  alert_test.log alert_test.bkp |egrep  "immediate|normal|abort|transactional|Starting ORACLE instance"|egrep -i "Shut|Start"|wc -l`
 if [ $x -gt 0 ]
 then
  echo $x
else
  echo "$x"
 fi
cp alert_test.log alert_test.bkp

Linux Tips

More Linux Questions

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.