期望脚本在单独调用时有效,但不能作为盐状态 [英] expect script works while invoking individually but not as a salt state
问题描述
我正在尝试通过期望做scp以及ssh.如果我像/usr/bin/expect myexpect.sh
这样直接从终端调用它,则下面的脚本有效,但是当我使用salt运行它时,第一个scp命令在第二个ssh失败的地方起作用.
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
相关的盐状态看起来像
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
仅在stdin位于tty/pty上时有效.
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.
这篇关于期望脚本在单独调用时有效,但不能作为盐状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!