Linux 除了脚本和ssh之外
我已经实现了expect脚本,以在一些服务器上自动化ssh连接 当ssh第一次尝试打开与服务器的连接时出现问题,我得到一个是/否问题 我必须先手动执行连接,然后它将不会再次出现,脚本工作良好 第一:我需要你的帮助,在expect脚本中找到跳过这个问题的步骤,这可能吗Linux 除了脚本和ssh之外,linux,shell,expect,Linux,Shell,Expect,我已经实现了expect脚本,以在一些服务器上自动化ssh连接 当ssh第一次尝试打开与服务器的连接时出现问题,我得到一个是/否问题 我必须先手动执行连接,然后它将不会再次出现,脚本工作良好 第一:我需要你的帮助,在expect脚本中找到跳过这个问题的步骤,这可能吗 以下是一个例子: #!/usr/bin/env expect spawn ssh root@127.0.0.1 while {1} { expect "(yes/no)?" { send "yes\r"
#!/usr/bin/env expect
spawn ssh root@127.0.0.1
while {1} {
expect "(yes/no)?" {
send "yes\r"
} "password: " {
send "xxxxxxxx\r"
interact
exit 0
}
}
`sshpass -p xxxxxxxx ssh root@127.0.0.1`
Generate a key pair, id_dsa.pub id_dsa with following command:
ssh-keygen -t dsa -b 1024
Move id_dsa to client:/home/xxxx/.ssh/
Move id_dsa.pub to server:/home/xxxx/.ssh/, and "cat id_dsa.pub >> authorized_keys"
chmod 600 /home/xxxx/.ssh/* (both the id_dsa and remote authorized_keys)
设置超时30
生成ssh-o“StrictHostKeyChecking no”“$usr@$ip”
期待{
“RSA密钥指纹”{send“yes\r”;exp\u continue}
-重新“{send”yes\r;exp\u continue}
“assword:{发送“$password\r”}
}
睡眠5
互动
将在超时时间(30秒)之前保持所有内容处于循环中。然后它将移动到脚本中的下一行。我还添加了一个expect for RSA,以防您需要它 -oStrictHostKeyChecking=no-oCheckHostIP=no仅将此添加到ssh即可解决此问题,谢谢:)
set timeout 30
spawn ssh -o "StrictHostKeyChecking no" "$usr@$ip"
expect {
"RSA key fingerprint" {send "yes\r"; exp_continue}
-re "<regex for whatever the yes/no question is>" {send "yes\r"; exp_continue}
"assword:" {send "$password\r"}
}
sleep 5
interact