linux-expect

Expect是一个用来处理交互的命令。借助Expect,我们可以将交互过程写在一个脚本上,使之自动化完成。
Expect中最关键的四个命令是send,expect,spawn,interact。
send:用于向进程发送字符串
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互

shell脚本实现ssh自动登录远程服务器示例:

#!/usr/bin/expect
spawn ssh [email protected]
expect "*password:"
send "123\r"
expect "*#"
interact

发布了52 篇原创文章 · 获赞 2 · 访问量 6374

猜你喜欢

转载自blog.csdn.net/wenwang3000/article/details/99640431