-1

I am new to using expect. I try the code below and it fails:

expect -c 'spawn ssh user@host < script.ecma3  
expect Password: ;
send "******\r";
send "exit\r";'    

anyone could clarify

nponeccop
  • 13,527
  • 1
  • 44
  • 106
  • 1
    Possible duplicate of [Expect within bash script](http://stackoverflow.com/questions/42353148/expect-within-bash-script) – mihir6692 Mar 15 '17 at 21:29

1 Answers1

0

This might help you

#!/usr/bin/expect
set timeout -1

spawn -noecho bash -c "ssh -t user@host '<here-comes-your-command>'"

expect {
  -re ".*assword.*" {
    exp_send "$env(PASS_WORD)\n"
    exp_continue
  }
}

Note :-

1) Copy script to remote host before running it. passing whole script is not good thing to do.

2) to access enviornment variables in expect , $env(variable_name) is used.

In above example , for $PASS_WORD, i used $env(PASS_WORD) .

mihir6692
  • 177
  • 1
  • 4
  • 19