我有一个奇怪的问题我正在尝试ssh连接到脚本内的远程设备,所以我可以向它发送命令,但奇怪的是它在我甚至可以调用expect命令之前要求输入ssh连接的密码。我的片段是这样的:
@startuml
package SomeGroup {
class "LocalStorageHandler" {
}
database "LocalStorage" {
}
}
@enduml
我得到的输出是:
#!/usr/bin/expect
set PASS="password"
echo {$PASS}
ssh admin@10.3.0.1 -p 4118 #Firewall Device IP
expect {
"Password: "
{send '$PASS\r'}
}
我不知道它为什么会这样。
编辑: 我已应用@glenn jackman建议的更改,新代码为:
password
Password:
通过这些更改,我收到错误:
#!/usr/bin/expect
set PASS "peak1234"
puts "$PASS"
ssh admin@10.3.0.1 -p 4118 #Firewall Device IP
expect "Password :"
send "$PASS\r"
答案 0 :(得分:3)
你用sh
混淆了期望#!/usr/bin/expect
set PASS "password" ; ## no "="
puts $PASS ; ## no "echo", braces wrong
ssh admin@10.3.0.1 -p 4118
expect "Password: "
send "$PASS\r" ; ## single quotes have no meaning in expect/Tcl