1.安装expect
yum -y install expect
2.编写expect脚本,以exp结尾。
vim test.exp
#!/usr/bin/expect
spawn ssh root@192.168.80.130
expect "yes/no"
send "yes\n"
expect "password"
send "123\n"
expect "#"
send "ifconfig\n"
send "exit\r"
expect eof
3.正式运行
expect test.exp
4.小结
- spawn的作用是启动新的进程
- expect的作用是从进程接收字符串
- send作用是用于向进程发送字符串
- expect是一个免费的编程工具,是一套用来实现自动交互功能的软件, expect 是 由Don Libes基于Tcl(ToolCommand Language )语言开发的。