Linux 系统安装自动化交互工具 Expect 及使用
简介
Expect是一个用来实现自动交互功能的软件套件,可以根据程序的提示模拟标准输入提供给程序需要的输入来实现交互程序执行。
通俗的说就是替代原来需要人工输入的步骤。
CentOS 7 安装并使用 expect
# 安装
yum -y install expect
# 撰写脚本
vi test.exp
#!/usr/bin/expect -f
# Spawn the SSH session
spawn telnet IP
# Expect the password prompt and send the password
expect "login : "
send "admin\r"
expect "password : "
send "ps\r"
# Expect the prompt and send some commands
expect ">"
send "执行命令\r"
expect ">"
send "继续执行命令\r"
expect ">"
# Close the session
send "exit\r"
expect eof
# 执行脚本
expect test.exp