系统环境
centos7
yum -y install expect
shell脚本
#!/usr/bin/expect
spawn ssh root@192.168.190.129
#执行命令
expect
{
"(yes/no)?"{ send "yes/r";exp_continue}
#匹配关键字后执行命令
"password:"{ send "123456\r"}
}
expect"]#"
send "ifconfig\r"
send "exit\r"
#退出
expect eof
本文介绍如何在CentOS7系统环境下使用expect脚本实现自动化SSH登录及命令执行流程,包括处理SSH首次连接确认及输入密码的过程,最后演示了发送ifconfig命令并安全退出的完整操作。
1070

被折叠的 条评论
为什么被折叠?



