模拟来自用户的 "enter" 按钮的命令
Command for simulating "enter" button from the user
我正在寻找一种在 tcl expect 中模拟按下 "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
中提取它包含的所有单词,并尝试将它们作为用户@exemple.net 的密码;
代码有效,但在上面代码的这一行之后 expect "user@example.net's password:"
我需要手动按下 "enter" 按钮然后脚本继续下一次尝试。
如何模拟这个输入。有没有模拟它的命令?
我是 tcl expect 的新手。谢谢你的时间。
尝试改变
send $i
至
send "$i\n"
例如使用此代码:
#!/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 "$password\n"
interact
}
{The authenticity of host*} {
send "yes\n"
expect {
{*password: } {
send "$password\n"
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
}
我正在寻找一种在 tcl expect 中模拟按下 "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
中提取它包含的所有单词,并尝试将它们作为用户@exemple.net 的密码;
代码有效,但在上面代码的这一行之后 expect "user@example.net's password:"
我需要手动按下 "enter" 按钮然后脚本继续下一次尝试。
如何模拟这个输入。有没有模拟它的命令? 我是 tcl expect 的新手。谢谢你的时间。
尝试改变
send $i
至
send "$i\n"
例如使用此代码:
#!/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 "$password\n"
interact
}
{The authenticity of host*} {
send "yes\n"
expect {
{*password: } {
send "$password\n"
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
}