批次起停資料庫指令碼

pentium發表於2013-05-02
unix 伺服器上可能有10多個資料庫,可以用指令碼批次啟動,停止 : start_all_dbs.sh, shutdown_all_dbs.sh.[@more@]*****************************************************************************************
start_all_dbs.sh
*****************************************************************************************

#!/bin/ksh

ORATAB=/var/opt/oracle/oratab; export ORATAB
TEMP_DIR=/tmp ; export TEMP_DIR

function is_db_up
{
rm $TEMP_DIR/delme.log
sqlplus "/ as sysdba"<< EOF > $TEMP_DIR/delme.log
exit
EOF
export DB_UP=F
grep "ORA-01034" $TEMP_DIR/delme.log >> /dev/null
if [ $? -eq 0 ] ; then
DB_UP=F
fi
rm $TEMP_DIR/delme.log
}

function startupdb_sqlplus
{
echo calling sqlplus
# get path/names of all database files for this database
sqlplus "/ as sysdba" <startup
EXIT
EOF
}


SID_LIST=`awk -F: '/^[^#]/ {printf " %s ",$1} END {printf "n"}' $ORATAB`
for SID in `echo $SID_LIST`
do
export ORACLE_SID=$SID
is_db_up
if [ "$DB_UP" = "T" ]; then
echo "***************** $ORACLE_SID is up already - no need to startup"
else
echo "**************** Starting $SID $ORACLE_HOME "
startupdb_sqlplus
fi
#check_alert_log
done


*****************************************************************************************
shutdown_all_dbs.sh
*****************************************************************************************


#!/bin/ksh

ORATAB=/var/opt/oracle/oratab; export ORATAB
TEMP_DIR=/tmp ; export TEMP_DIR


function shutdowndb_sqlplus
{
echo calling sqlplus
# get path/names of all database files for this database
sqlplus "/ as sysdba" <shutdown immediate
EXIT
EOF
}


SID_LIST=`awk -F: '/^[^#]/ {printf " %s ",$1} END {printf "n"}' $ORATAB`
for SID in `echo $SID_LIST`
do
export ORACLE_SID=$SID

shutdowndb_sqlplus

done

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14377/viewspace-1060456/,如需轉載,請註明出處,否則將追究法律責任。

相關文章