我需要使用oracle sudo调用sqlplus
,通过一行命令明确指定DB (env ORACLE_SID
)。通常的方法包括两个步骤:
$ sudo -u oracle -i
$ ORACLE_SID=DBNAME sqlplus / as sysdba
但我需要用一行来做(为了节省时间,合理)。我试着简单地这样做:
$ sudo -u oracle -i ORACLE_SID=DBNAME sqlplus / as sysdba
但是,sqlplus
似乎没有看到ORACLE_SID
env的变化,并连接到默认DB。此外,我不能排除-i
sudo选项,因为我需要确保所有其他环境变量都已完全初始化。
在我的情况下,如何使用sudo和自定义环境变量运行应用程序?
发布于 2018-03-16 02:32:28
解决问题的最佳方法是使用以下命令:
sudo -u oracle -i sh -c "ORACLE_SID=DBNAME sqlplus / as sysdba"
如果我们想在一行中直接传递sql脚本:
sudo -u oracle -i sh -c "ORACLE_SID=DBNAME sqlplus / as sysdba" <<-EOF
SELECT 1 FROM DUAL;
EOF
发布于 2018-03-01 07:17:40
尝试以下命令:
sudo -i su - oracle -c 'ORACLE_SID=DBNAME && sqlplus'
解释:
"sudo -i" will take care of the environment variables.
"su - user" will consider the user's environment variables
"-c" -> the command you wish to issue.
https://serverfault.com/questions/899494
复制相似问题