简体   繁体   English

运行shell脚本以root用户身份连接到Oracle时出错

[英]Error while running shell script to connect to Oracle as root user

I have a shell script file(Oracle_UserData.sh) on my ubuntu VM (shows below), 我的ubuntu VM上有一个Shell脚本文件(Oracle_UserData.sh)(如下所示),

#!/bin/bash
echo "login to oracle 11g as sys"
chmod -R 755 /u01/app/oracle/product/11.2.0/xe
/u01/app/oracle/product/11.2.0/xe/bin/sqlplus -S sys/password as sysdba <<EOF
        create user $USER identified by $PASSWORD;
        grant all privileges to $USER;
        exit;
EOF

and I have another script file that runs as root, which would trigger the previous script file to run. 而且我还有另一个脚本文件,该文件以root身份运行,这将触发先前的脚本文件运行。 (It runs as root because I'm passing the script as part of the Amazon EC2 user data). (它以root用户身份运行,因为我将脚本作为Amazon EC2用户数据的一部分进行了传递)。

#!/bin/bash
export USER=root
export PASSWORD=password

cd "/home/ubuntu/"
sh Oracle_UserData.sh
output: {all: '| tee -a /var/log/cloud-init-output.log'}

I am trying to create a new db user by running the these scripts, but it failed. 我试图通过运行这些脚本来创建新的数据库用户,但是失败了。 I'm not sure if it's because the root user cannot access the environment variable or some other issue? 我不确定是否是因为root用户无法访问环境变量或其他问题? I got the error 我得到了错误

Error 6 initializing SQL*Plus

I tried to make those environment variable as a local variable by exporting them (ORACLE_HOME, ORACLE_BASE, ORACLE_SID), and I got the error that 我试图通过导出它们(ORACLE_HOME,ORACLE_BASE,ORACLE_SID)使这些环境变量成为局部变量,但出现错误消息

ORA-12547: TNS:lost contact

(If I just make this script as a local file, and run it locally as Ubuntu, it works fine. User can be created with no issue.) (如果我只是将此脚本制作为本地文件,然后以Ubuntu本地运行,则可以正常工作。可以毫无问题地创建用户。)

Can anyone help? 有人可以帮忙吗?

I got the problem solved by following the link below, http://www.dadbm.com/how-to-fix-ora-12547-tns-lost-contact-when-try-to-connect-to-oracle/ 我可以通过下面的链接http://www.dadbm.com/how-to-fix-ora-12547-tns-lost-contact-when-try-to-connect-to-oracle/来解决问题

cd $ORACLE_HOME/bin

ls -ltr oracle
-rwxr-xr-x    1 oracle   oinstall       136803483 Mar 16 20:32 oracle

chmod 6751 oracle

ls -ltr oracle
-rwsr-s--x    1 oracle   oinstall       136803483 Mar 16 20:32 oracle   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM