expect script works while invoking individually bu

2019-08-23 04:09发布

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条回答
forever°为你锁心
2楼-- · 2019-08-23 05:10

I know nothing about 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.

查看更多
登录 后发表回答