Operating System - HP-UX
1748180 Members
3954 Online
108759 Solutions
New Discussion юеВ

Re: Help with Oracle 9i startup/shutdown script

 
Cara Tock
Regular Advisor

Help with Oracle 9i startup/shutdown script

I want to automate my HP Data Protector 5.5 Oracle cold backups with pre-exec and post-exec scripts for startup and shutdown.

While the commands to startup/shutdown Oracle 9i work from the command line/shell, when the commands are put in a Korn shell script, the script prompts for a password.

Does anyone have Oracle 9i startup/shutdown script advice/examples that I could view?

Please help!

Regards, Cara
9 REPLIES 9
Indira Aramandla
Honored Contributor

Re: Help with Oracle 9i startup/shutdown script

Hi Cara,

Check your path and all the environment variables are defined and exported. Usually if you can run manually but not through cron it goes back to environment initialisation.
Cron does not run profile therefore it's up to you to initialise the variables in the script.

TO shutdown the database before the cold backup you can invoke the $ORACLE_HOME/bin/dbshut and to start the database fater the backup invoke $ORACLE_HOME/bin/dbstart.

IA

Never give up, Keep Trying
Yogeeraj_1
Honored Contributor

Re: Help with Oracle 9i startup/shutdown script

hi cara,

for more guidance on the scripts and environment settings that you might require, please see also:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=983721

hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Peter Godron
Honored Contributor

Re: Help with Oracle 9i startup/shutdown script

Cara,
please ensure your environment is the same from the command line and within the script.
Also, are you running the script as oracle or root? If you run it as root, please make sure you use "su - oracle". The minus sign ensures your login goes through the same scripts as if you had logged in directly.
Arturo Galbiati
Esteemed Contributor

Re: Help with Oracle 9i startup/shutdown script

Hi Clara,
if you want to start/stop all the databases you have at the startup/shutdown of the server you have to use:
$ORACLE_HOME/bin/dbstart
$ORACLE_HOME/bin/dbshut
in etc/rc* files.

Instead if you want to start/stop a single database in a script for your use, let me know and I adapt the standard oracle script for you.

HTH,
Art
rariasn
Honored Contributor

Re: Help with Oracle 9i startup/shutdown script

Hi Clara;

BACKUP OFFLINE: (with user oracle)

SHUTDOWN:

. /home/oracle/conf/profile_$instance
sqlplus /nolog <connect / as sysdba
shutdown immediate
exit;
EOF
exit 0

STARTUP:
. /home/oracle/conf/profile_$instance
sqlplus /nolog <connect / as sysdba
startup pfile=
/oracle1/$instance/init$instance.ora
exit;
EOF
exit 0

BACKUP ONLINE:

Put all tablespaces in mode "begin backup":

alter tablespace $NAME_TABLESPACE begin backup;

When you ended your backup:

alter tablespace $NAME_TABLESPACE end backup;


Xiaogang Zheng
Advisor

Re: Help with Oracle 9i startup/shutdown script

Hi Cara,

Oracle provide a role 'sysoper' for startup/shutdown instances purpose.
You can create a user and grant sysoper to this user. Then you can put the username/password in the scripts. The role do not has other system privilege and don't need to worry if you hard-code the password in your script.

If the server has many users and only you (Oracle DBA) can connect by using "connect / as sysdba" instead of "connect username/password as sysdba", you can protect the scripts on OS level.


The following is a sample. 'startup_dev2.sh'

. /home/oracle/chg817.sh

LOGDIR=/u01/app/oracle/admin/dbascript/log
ORACLE_SID=dev2
LOGS=$LOGDIR/startup_"$ORACLE_SID".log

export LOGDIR ORACLE_SID LOGS

date >> $LOGS

echo "Starting up dev2 ..."
sqlplus /nolog >> $LOGS << EOF
whenever sqlerror exit 1
connect dboper/dev2_dboper AS SYSOPER;
show user;
startup;
EOF

export ERROR_FLAG=$?
if [ $ERROR_FLAG != "0" ]
then
echo "The dev2 can not be started up !"
echo "The dev2 can not be started up !" >> $LOGS
else
echo "The dev2 has been started up !"
echo "The dev2 has been started up !" >> $LOGS
fi

date >> $LOGS
Cara Tock
Regular Advisor

Re: Help with Oracle 9i startup/shutdown script

Art - Yes, I am interested in starting/stopping a single instance of Oracle 9i. If you could provide me with an example, I would be very grateful. Please note: If possible, myself & the DBA do not want a plain text password as part of the script. Please let me know if this is possible. You could post the info or email me at cara.tock@bcw.edu.

Thank you to all who posted. I will review with the DBA & then respond more & assign points.

Regards, Cara
Xiaogang Zheng
Advisor

Re: Help with Oracle 9i startup/shutdown script

Hi Cara,

1. You don't want to have the prompt for a password when you run shell scripts.
2. Shutdown/start instance need to connect first.
3. Connect to database need a username/password.
4. shell script is a plain text file.

So, if you don't want to put password on scrips, and don't want to see the prompt, the only one way is to put 'connect / as sysdba' in your scripts. But the OS users (they may be operators/sysadmin/dba) who need to run the scripts must belong to OracleDBA group. This setting has more potential problems if the os user login to system he/she can connect to database directly as sysdba without protection. I don't think your DBA would like it.

However, the user who connected AS SYSOPER can only Perform STARTUP and SHUTDOWN, it will not hurt the database. I believe you have method to protect the scripts.

Best Regards
Xiaogang
Simon Wickham_6
Regular Advisor

Re: Help with Oracle 9i startup/shutdown script

This script is used to start ORACLE from /etc/rc(.local).
It should ONLY be executed as part of the system boot procedure.

-------------#### Script Begins

$Header: dbstart.sh.pp 09-dec-99.09:51:46 mdenney Exp $ dbstart.sh.pp Copyr (c) 1991 Oracle
#

###################################
#
# usage: dbstart
#
# This script is used to start ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
#####################################

ORATAB=/etc/oratab

trap 'exit' 1 2 3
case $ORACLE_TRACE in
T) set -x ;;
esac

# Set path if path not set (if called from /etc/rc)
case $PATH in
"") PATH=/bin:/usr/bin:/etc
export PATH ;;
esac

#
# Loop for every entry in oratab file and and try to start
# that ORACLE
#

cat $ORATAB | while read LINE
do
case $LINE in
\#*) ;; #comment-line in oratab
*)
# Proceed only if third field is 'Y'.
if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] ; then
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
if [ "$ORACLE_SID" = '*' ] ; then
ORACLE_SID=""
fi
# Called programs use same database ID
export ORACLE_SID
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
# Called scripts use same home directory
export ORACLE_HOME
# Put $ORACLE_HOME/bin into PATH and export.
PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc ; export PATH
# add for bug # 652997
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ORACLE_HOME}/lib ; export LD_LIBRARY_PATH

PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora

# Figure out if this is a V5, V6, or V7 database. Do we really need V5?
if [ -f $ORACLE_HOME/bin/sqldba ] ; then
VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
/SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;
print V[1]}'`
else
if test -f $ORACLE_HOME/bin/svrmgrl; then
VERSION=`$ORACLE_HOME/bin/svrmgrl command=exit | awk '
/Edition Release/ {substr($5,1,3) ;
print substr($5,1,3)}'`
else
VERSION="8.2"
fi
fi

STATUS=1
if [ "$VERSION" = "8.1" ]
then
pmon=`ps -ef | egrep pmon_$ORACLE_SID | grep -v grep`
if [ "$pmon" != "" ];
then
STATUS="-1"
echo "Database \"${ORACLE_SID}\" already started."
fi
else
if test -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf -o \
-f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora
then
STATUS="-1"
else
STATUS=1
fi
fi

case $STATUS in
1) if [ -f $PFILE ] ; then
case $VERSION in
6) sqldba command=startup
;;

7) sqldba <connect internal
startup
EOF
;;

7.3) svrmgrl <connect internal
startup
EOF
;;
8.0) svrmgrl <connect internal
startup
EOF
;;
8.1) sqlplus /nolog <connect internal
startup
EOF
;;
esac

if test $? -eq 0 ; then
echo ""
echo "Database \"${ORACLE_SID}\" warm started."
else
echo ""
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo ""
echo "Can't find init file for Database \"${ORACLE_SID}\"."
echo "Database \"${ORACLE_SID}\" NOT started."
fi
;;

-1) echo ""
echo "Database \"${ORACLE_SID}\" possibly left running when system went down (system crash?)."
echo "Notify Database Administrator."
case $VERSION in
6) sqldba "command=shutdown abort"
;;

7) sqldba <connect internal
shutdown abort
EOF
;;

7.3) svrmgrl <connect internal
shutdown abort
EOF
;;
8.0) svrmgrl <connect internal
shutdown abort
EOF
;;
8.1) sqlplus /nolog <connect internal
shutdown abort
EOF
;;

esac

if test $? -eq 0 ; then
if [ -f $PFILE ] ; then
case $VERSION in
6) sqldba command=startup
;;

7) sqldba <connect internal
startup
EOF
;;
7.3) svrmgrl <connect internal
startup
EOF
;;
8.0) svrmgrl <connect internal
startup
EOF
;;
8.1) sqlplus /nolog <connect internal
startup
EOF
;;

esac
if test $? -eq 0 ; then
echo ""
echo "Database \"${ORACLE_SID}\" warm started."
else
echo ""
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo ""
echo "Can't find init file for Database \"${ORACLE_SID}\"."
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo "Database \"${ORACLE_SID}\" NOT started."
fi
;;
esac
fi
;;
esac
done

---------------------------## Script Ends

Regards,
Simon