ANT SSHEXEC密码提示问题与su -c

时间:2012-10-19 14:23:32

标签: shell ant ssh automation build-automation

我试图绕过并发出ANT / SSHEXEC命令。

设置:

使用NIS和基于角色的用户进行运行时活动的Solaris服务器。

您无法直接登录RBAC帐户,您必须以个人用户身份和su连接到用户 - 我被告知在此环境中不能选择SUDO。

因此,我正在构建一些ANT脚本来构建,部署然后在远程服务器上运行一组脚本。

构建和部署很好,因为这是作为我的用户执行的,但是当尝试使用SSHEXEC连接到su -c $ user时,我遇到了一个问题,即shell响应密码提示,但我无法输入任何东西。

所以在这里,我要么想要一个解决方案,让我输入密码并继续,或者将密码作为我输入的变量传递给提示符。

以下是我目前使用的代码:

<target name="install-products">
  <sshexec host="${remote.host1}" 
    username="${remote.user}" 
    password="${remote.pwd}"
    command="/usr/bin/su - $user -c cd ${remote.install.dir}/OracleSunJDK;./installJAVA.sh -p project -e 935"
    usepty="true"
    trust="true"
    failonerror="true"/>
</target>

所以我作为我的用户连接,例如ssh -t cambolie @ $ {remote.host1} ...用户和密码如上所述传递,其su -c然​​后导致提示出现。

目前正在发生这种情况:

install-products:
[sshexec] Connecting to ${remote.host1}:22
[sshexec] cmd : /usr/bin/su - ${su-user}  -c cd /var/tmp/weblogic/RP_WEBLOGIC_J2EE_1.0.0.0/install/OracleSunJDK;./installJAVA.sh -p project -e 935
[sshexec] Password:

它只是在这个阶段挂起。

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

以下是可能的解决方案之一。

  1. 从主机向目标计算机设置基于密钥的scp
  2. 将构建脚本修改为scp标记文件(即begin.install,零字节文件)
  3. 在目标计算机上设置一个cron以查找标记文件,找到后,启动要在该服务器上执行的一组步骤。完成后,删除标记文件。

答案 1 :(得分:0)

这对我有用:

   <property name="password" value="MYPASS"/>

    <!-- Keep the closing property tag on the new line as su needs the CR/LF-->
    <property name="password.crlf">${password}<!-- do not remove the CR/LF-->
    </property>
    <!-- Keep the closing property tag on the new line as su needs the CR/LF-->

  <sshexec host="${server}"
                 username="${username1}"
                 password="${password1}"
                 trust="yes"
                 verbose="yes"
                 usepty="true"
                 inputproperty="password.crlf"
                 command="su - otheruser -c ls"
        />
相关问题