Você está na página 1de 4

WORKING IN OTHER ORACLE DATABASES

Author JP Vijaykumar
Date 07-14-2010
As an Oracle DBA I will be connecting to multiple databases on multiple unix ser
vers.
At any given time, I will be managing multiple databases on multiple servers.
For each remote database, connecting to the server through putty and then connec
ting
to the oracle database through sqlplus is a painful process. To make thing short
and
easy, I use these scripts.
The version of our databases is Oracle 10.2.0.4. The Os on the servers is HP Un
ix.
These scripts may not work, if the servers are spread across different network d
omains.
If there are stringent firewall policies exist for inter connectivity between se
rvers,
these scripts may not work. As per your environment, necessary changes are to be
made
to these scripts befor use.
I had the following script available on all the unix servers.
$ cat login.sh
#!/usr/bin/ksh
if [[ $# -eq "1" ]]; then
export ORACLE_SID=`echo $1|tr 'a-z' 'A-Z'`
if [[ $(ps -ef|grep smon|grep -v grep|grep ${ORACLE_SID}|wc -l) > "0" ]]; then
export ORACLE_HOME=`cat /etc/oratab|grep -v grep|grep ${ORACLE_SID}|cut -d":" -f
2`
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
$ORACLE_HOME/bin/sqlplus "/as sysdba"
else
echo "The db is down or wrong db name. Pls verify "
fi
exit
else
echo "usage login.sh ORACLE_SID"
exit;
fi
exit
----------------------------------------------------------
$ login.sh prod1
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jun 3 12:20:58 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
**********************************************************
I had created this script on a development server, from this development server,
I regularly connect to all the production databases, as and when needed.
$ cat login_prod.sh
#!/usr/bin/ksh
cd /home/oracle/scripts
export ORACLE_HOME=/u107/oracle/product/10.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
$ORACLE_HOME/bin/sqlplus system/manager@$1
exit
----------------------------------------------------------
$ login_prod.sh prod2
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jun 3 12:22:04 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select host_name from v$instance;
HOST_NAME
-----------------------------------------------------------
oralinux
SQL> !hostname
oralinux
**********************************************************
Regularly, I will be checking for various paramaters accross our production data
bases.
It is very difficult and time consuming to connect to each of the numerous datab
ases
and check for various parameters day in and day out.
I had these scripts to achieve these requirements.
$ cat sid_list
prod1
prod2
prod3
prod4
$ cat sid_loop.sh
#!/usr/bin/ksh
#cat /etc/oratab|grep -v "^#"|while read LINE
cat sid_list|grep -v "^#"|while read LINE
do
export ORACLE_SID=`echo $LINE|tr 'a-z' 'A-Z'`
export ORACLE_HOME=/u001/oracle/product/10.2.0/db_1

$ORACLE_HOME/bin/sqlplus -s system/manager@$ORACLE_SID >> jp.log <<EOF


set pagesize 0 linesize 200 echo off feedback off
set head off
--select name from v\$database;
select to_char(sysdate,'mm-dd-yyyy hh24:mi:ss')||' '||name from v\$database;
--spool off
EOF
done
exit

$ rm -f jp.log

$ sid_loop.sh

$ cat jp.log
06-03-2010 12:25:11 PROD1
06-03-2010 12:25:11 PROD2
06-03-2010 12:25:11 PROD3
06-03-2010 12:25:12 PROD4

******************************************************
This scrpt loops through the sidserdir.lst file captures the variables sid name,
server name and the location of the rman log file and scans for errors
Assuming there will be only one rman*log files will be existing in the RMANDIR d
irectory
on the remote server.
Assuming the rsh feature is available on all the unix servers.
#!/usr/bin/ksh
export DIR=u001/oracle/cron_scripts
export FILELIST=$DIR/sidserdir.lst
export ERRORLOG=$DIR/rman_today_log
mv $ERRORLOG $DIR/rman_yesterday_log
for LINE in `cat $FILELIST`
do
export SID=`echo $LINE|cut -d":" -f1`
export SERVER=`echo $LINE|cut -d":" -f2`
export RMANDIR=`echo $LINE|cut -d":" -f1`
if [[ $(rsh $SERVER cat $RMANDIR/rman*log|grep "ERROR STACK"|grep -v grep|wc -1)
> 0 ]]; then
echo "rman backup of $SID on $SERVER on `date` failed with errors" >> $ERR
ORLOG
rsh $SERVER tail -25 $RMANDIR/rman*log >> $ERRORLOG
fi
done
exit
******************************************************
References
http://www.oreillynet.com/pub/a/oreilly/oracle/news/unix_oracle_0101.html
http://www.databasejournal.com/scripts/article.php/3810526/Login-Script.htm

Você também pode gostar