我正在寻找一种在tcl中期望模拟按下"enter"脚本的方法(例如,在一些输出脚本停止后,只有在我手动按下"enter"之后,它才进一步)它等待从用户按下"enter"键,然后继续输出剩余的脚本。
这里是我的代码,我有这个问题:
set timeout 20
set f [open "password.txt" r]
set password [read $f]
close $f
foreach i $password {
puts "trying this as a pass : $i"
spawn ssh user@exemple.net -p 724
expect "user@exemple.net's password:"
send $i
interact
}
此代码从password.txt
中获取其包含的所有单词,并尝试将它们作为user@exemple.net的密码;代码工作,但在expect "user@example.net's password:"
以上代码的这一行之后,我需要手动按"enter"按钮,然后脚本将与下一次尝试。
如何模拟这个输入?有没有类似的命令?我是新来的。感谢您的宝贵时间。
尝试更改
send $i
send "$in"
使用如下代码:
#!/usr/bin/expect
# Set the time allowed to wait for a given response. SEt to 30 seconds because it can take a while
# for machines to respond to an ssh request.
set timeout 30000
proc connectToServer { user host password port } {
set address $user
append address "@"
append address $host
puts "Connecting to server: $host"
spawn ssh $address -p $port
expect {
{*password: } {
send "$passwordn"
interact
}
{The authenticity of host*} {
send "yesn"
expect {
{*password: } {
send "$passwordn"
interact
}
}
}
"*No route to host" { puts "No route to host" }
eof {puts "Woops there was an eof"}
timeout {puts "Timed out"}
}
}
if {$argc < 3} {
puts "Error - you need to provide at least 3 arguments"
puts "* user"
puts "* host"
puts "* password"
puts "* port - optional"
} else {
set user [lindex $argv 0];
set host [lindex $argv 1];
set password [lindex $argv 2];
# setting port argument is optional
if {$argc > 3} {
set port [lindex $argv 3];
} else {
set port 22
}
connectToServer $user $host $password $port
}