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
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
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)
.