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

≡放荡痞女 提交于 2019-12-13 03:02:06

问题


I'm trying to do scp as well as ssh through expect. Below script works if I invoke it directly from terminal like /usr/bin/expect myexpect.sh but when I ran it using salt, the first scp command works where the second ssh fails.

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

Relevant salt state looks like,

st.sls

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

回答1:


I know nothing about salt-stack but I suspect it's not running your Expect script from a pty. So replace interact with expect eof (or expect -timeout 12345 eof if necessary). interact works only when stdin is on a tty/pty.



来源:https://stackoverflow.com/questions/50698791/expect-script-works-while-invoking-individually-but-not-as-a-salt-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!