【问题标题】:remote sql script from jenkins来自詹金斯的远程 sql 脚本
【发布时间】:2017-03-02 16:59:37
【问题描述】:

我想运行一个远程盒子中的 sql 脚本,在使用用户 ID 和密码连接到盒子后,手动步骤如下
然后sudo su – fa3dev

账号密码:*******

sqlplus / as sysdba

连接XX_fusion_custom

密码* ****

@abc.sql
当我手动运行时,一切正常 当我从 jenkins 作为远程 shell 脚本运行时,如下所示

ssh fa3dev@server 'source .bash_profile; sqlplus xx_fusion_custom/password'

在控制台中,它使 Sql 连接和断开

如果我运行 ssh fa3dev@server 'source .bash_profile; sqlplus xx_fusion_custom/password;sqlplus / as sysdba;connect XX_fusion_custom;select user from dual' 它在 jenkins 控制台中出现意外令牌“来自”附近的语法错误,我想我无法连接到数据库,这方面的任何帮助都非常有用,我无法使用 SQL 插件,因为我无法在 jenkins 框中安装 oracle cleint

【问题讨论】:

标签: oracle jenkins ssh


【解决方案1】:

您的问题出在 bash 中,在 sqlplus 退出后正在执行 sql 命令 select user from dual,并且 bash 将其拾取。

您可以通过两种方式解决此问题:

  1. echo进入sqlplus:

    ssh fa3dev@server 'source .bash_profile; echo select user from dual | sqlplus xx_fusion_custom/password;sqlplus / as sysdba;connect XX_fusion_custom;'

  2. 使用命令传递文件(如果 SQL 命令很多且固定,这很好)

2.1 远程文件

ssh fa3dev@server 'source .bash_profile; sqlplus xx_fusion_custom/password;sqlplus / as sysdba;connect XX_fusion_custom < files_with_commands.sql'

2.2 本地文件(注意关闭'的位置从hfilename之后变成了filename之前):

ssh fa3dev@server 'source .bash_profile; sqlplus xx_fusion_custom/password;sqlplus / as sysdba;connect XX_fusion_custom < files_with_commands.sql'

【讨论】:

  • 嗨@subrata-fouzdar,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
  • 我肯定会接受,但我没有选择接受它的选项,我猜原因是这个问题被 mod 标记为题外话,不确定为什么……
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多