expect 脚本在单独调用时有效,但不能作为盐状态

expect script works while invoking individually but not as a salt state

我正在尝试通过 expect 执行 scp 和 ssh。如果我直接从 /usr/bin/expect myexpect.sh 之类的终端调用它,下面的脚本就可以工作,但是当我 运行 它使用 salt 时,第一个 scp 命令在第二个 ssh 失败的地方工作。

myexpect.sh

#!/usr/bin/expect -f

set timeout 240

spawn scp apps.tar.gz /srv/salt/integration/serverclass_merged.conf foo@10.10.10.10:/home/foo
expect "password:"
send "password\n";
expect eof

spawn ssh -o StrictHostKeyChecking=no foo@10.10.10.10 "cd /home/foo;tar --strip-components=1 -xzvf apps.tar.gz -C /opt/apps/;cp serverclass_merged.conf /opt/local/serverclass.conf"
expect "assword:"
send "password\r"
interact

相关的盐状态看起来像,

st.sls

copy_apps:
  cmd.run:
    - name: /usr/bin/expect /home/ocdn_adm/myexpect.sh

我对 一无所知,但我怀疑它不是 运行 您来自 pty 的 Expect 脚本。因此,将 interact 替换为 expect eof(或 expect -timeout 12345 eof,如有必要)。 interact 仅在标准输入位于 tty/pty.

上时有效