shell脚本实现非交互ssh远程连接主机
作者:
南南宫问天 | 来源:发表于
2020-04-27 10:51 被阅读0次[root@db scripts]# cat expect02.sh
#!/usr/bin/expect
set ip 172.16.210.11 ##设置变量ip
set user root ##设置用户
set passwd redhat ##设置密码
set timeout 5 ##设置超时时间
spawn ssh $user@$ip ##发起一个会话
expect { ##接受会话并发送参数
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "$passwd\r" };
}
interact ##停留在对面的终端
[root@db scripts]# chmod + expect02.sh ##添加执行权限
[root@db scripts]# ./expect02.sh ##执行脚本
spawn ssh root@172.16.210.11
Last login: Mon Apr 27 10:31:06 2020 from 172.16.210.36
[root@master-11 ~]# ##连接成功
本文标题:shell脚本实现非交互ssh远程连接主机
本文链接:https://www.haomeiwen.com/subject/ghxywhtx.html
网友评论