对于那些想要回复我应该使用SSH密钥的人请弃权
我正在尝试在bash脚本中使用expect来提供SSH密码.提供密码是有效的,但我不会像我应该的那样在SSH会话中结束,它会回到海峡.
我的剧本:
#!/bin/bash
read -s PWD
/usr/bin/expect <<EOD
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no usr@$myhost.example.com'
expect "password"
send "$PWD\n"
EOD
echo "you're out"
Run Code Online (Sandbox Code Playgroud)
我脚本的输出:
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no usr@$myhost.example.com
usr@$myhost.example.com's password: you're out
Run Code Online (Sandbox Code Playgroud)
我想拥有我的SSH会话,只有当我退出它才能返回我的bash脚本.我之前使用bash的原因是因为我使用了一个菜单,我可以选择连接哪个单元.
谢谢
我写了一个期望内部的bash脚本,连接到终端服务器和清除行.我无法弄清楚我得到的错误,因为我已经给了所有必要的括号.我也不理解couldn't read file "line": no such file or directory错误.请帮助.
我的剧本:
#!/bin/bash
VAR=$(expect -c "
spawn telnet 1.1.1.1
expect {
"Password:" { send "password\r" ; exp_continue}
"Prompt>" { send "en\r" ; exp_continue}
"Password:" { send "password\r" ; exp_continue}
"Prompt#" {send "clea line 10\r" ; exp_continue}
"[confirm]" {send "Y\r" ; exp_continue}
"Prompt#" {send "clea line 11\r" ; exp_continue}
"[confirm]" {send "Y\r" ; exp_continue}
"Prompt#" {send "exit\r" }
}
")
echo $VAR
Run Code Online (Sandbox Code Playgroud)
它的输出:
missing close-brace
while executing
"expect"
couldn't read file …Run Code Online (Sandbox Code Playgroud)