我试图创建一个将登录到多个os用户的shell脚本,然后在多个数据库上执行sql脚本,但是出现以下错误。我知道oracle_home的输出设置不正确,但是我不知道如何解决它。
#!/bin/bash
printf "%6s %-20s %-80s\n" "PID" "NAME" "ORACLE_HOME"
pgrep -lf _pmon_ |
while read pid pname y ; do
export EXEC=$(ls -l /proc/$pid/exe | awk -F'>' '{ print $2 }'| sort | uniq)
export USER="$(ls -l $EXEC |awk '{ print $3 }'| sort | uniq)"
export ORACLE_SID="$(echo $pname |grep -v grep | cut -d '_' -f3)"
export ORACLE_HOME="$(ls -l /proc/$pid/exe | awk -F'>' '{ print $2 }' | sed 's/\/bin\/oracle$//')"
export PATH_RESET=$PATH
export PATH="$ORACLE_HOME/bin:$PATH"
sleep .5
sudo su - $USER <<EOF
echo ==========start $ORA_SID==========
#export "ORACLE_SID=$ORA_SID"
#export "ORACLE_HOME=$ORA_HOME"
#export PATH=$ORACLE_HOME/bin:$PATH"
"whoami"
echo $EXEC
echo Connecting to user: $USER SID: $ORACLE_SID
echo ORACLE_HOME: $ORACLE_HOME
echo $PATH
$ORACLE_HOME/bin/sqlplus "/ as sysdba" @/home/oraprod/db_name.sql
echo ==========end===================
echo " "
echo " "
exit
EOF
export PATH=$PATH_RESET
done
exit
错误:
==========start ==========
oraprod
/u01/app/oraprod/product/11.2.0.3/idm_home/bin/oracle
Connecting to user: oraprod SID: IDMDEV
ORACLE_HOME: /u01/app/oraprod/product/11.2.0.3/idm_home
/u01/app/oraprod/product/11.2.0.3/idm_home/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
==========end===================
==========start ==========
oraprod
/u01/app/oraprod/product/11.2.0.3/idm_home/bin/oracle
Connecting to user: oraprod SID: idmdb2
ORACLE_HOME: /u01/app/oraprod/product/11.2.0.3/idm_home
/u01/app/oraprod/product/11.2.0.3/idm_home/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
==========end===================