返回顶部

pzzning

导航

expect 安装使用

expect 命令相当于crt远程连接,可用于脚本化实现多服务器巡检功能。

一、expect 命令安装:

1、rpm 文件下载:百度云链接:http://pan.baidu.com/s/1sl1wSUh 密码:pjio

2、上传安装:

 rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm 
 rpm -ivh expect-5.44.1.15-4.el6.x86_64.rpm 

3、测试:

[root@localhost expect]# expect 
expect1.1> 
expect1.1> 

二、脚本应用:

1、新建测试脚本 expect_test.sh

#!/bin/bash
passwd='ningning'

/usr/bin/expect <<-EOF
set time 30
spawn ssh -p22 root@192.168.237.200
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect "*#"
send "useradd ningning\r"
expect "*#"
send "mkdir /opt/test\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF

 

posted on 2017-01-22 15:16  pzzning  阅读(996)  评论(0编辑  收藏  举报