Singl oracle 11g database shutdown immediate script

single_db_11g_shutdown_db.sh
####################################################################################################################
##This script is to perform database "shutdown immediate " and user process and transaction check before shutdown database .
##Steps performed during database shutdown:
##1.Verify user connection to database.
##2.Stop listener .
##2.Verify transaction.
##3.Shutdown database immediate .
####################################################################################################################
#!/bin/sh
##set oracle home environment
. /home/oracle/.bash_profile

##Check any user process connected to database before shutdown
ORA_PRO_CNT=`ps -ef | grep LOCAL=NO|grep -v grep|wc -l`

if [ $ORA_PRO_CNT -gt 0 ];
   then
echo "stop shutdown database,there are $ORA_PRO_CNT database connection ."
   exit
elif [ $ORA_PRO_CNT -eq 0 ];
   then
##stop listener before shutdown database
for i in $(ps -ef | grep tnslsnr|grep -v grep |awk '{print $9'} );
   do
lsnrctl stop "$i"
   done
fi
##Verify any transaction in database befere shutdown database
TRAN_STATUS_CNT=`sqlplus -s / as sysdba <
set pages 0 feedback off
select count(*) from v\\$transaction;
exit;
EOF`
if [ $TRAN_STATUS_CNT -gt 0 ];
   then
   echo "$TRAN_STATUS_CNT Transaction exists in database ,please close the transaction first before shutdown database"
exit
elif [ $TRAN_STATUS_CNT -eq 0 ];
   then
   echo "$TRAN_STATUS_CNT transaction exists in database ."
##Check any dead transaction in database
TRAN_DEAD_CNT=`sqlplus -s / as sysdba <
set pagesize 0 feedback off
select count(*) from x\\$ktuxe where ktuxecfl='DEAD';
exit;
EOF`
if [ $TRAN_DEAD_CNT -gt 0 ] ;
   then
   echo "$TRAN_DEAD_CNT dead transaction in database ,exit now ."
   exit
elif [ $TRAN_DEAD_CNT -eq 0 ];
   then
   echo "$TRAN_DEAD_CNT dead transaction in database.shutdown database now ."
`sqlplus -s / as sysdba <
shutdown immediate;
exit;
EOF`
fi
fi
请使用浏览器的分享功能分享到微信等