我是新手expect
。我尝试下面的代码,但它失败了:
expect -c 'spawn ssh user@host < script.ecma3
expect Password: ;
send "******\r";
send "exit\r";'
任何人都可以澄清
我是新手expect
。我尝试下面的代码,但它失败了:
expect -c 'spawn ssh user@host < script.ecma3
expect Password: ;
send "******\r";
send "exit\r";'
任何人都可以澄清
这可能会帮助你
#!/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
}
}
笔记 :-
1)在运行之前将脚本复制到远程主机。通过整个脚本不是一件好事。
2) 用于访问 expect 中$env(variable_name)
的环境变量。
在上面的例子中,对于$PASS_WORD
,我使用了$env(PASS_WORD)
.