shell结合expect的非交互式脚本
简单需求来讲解shell+expect
先安装下expect,yum安装
yum install expect -y
#!/bin/bash
ip='192.168.80.20' #定义远程交换服务器的IP
password='test@2015' #定义输入的密码
expect << EOF
spawn ssh root@$ip ls #在expect中执行命令
set timeout -1 #定义超时时间,-1为永不超时
expect "*:" #如果输出*:
set timeout -1
send "$password\r" #自动输入password
expect eof #结束
EOF
转载于:https://blog.51cto.com/yanjiu/1785172