expect脚本

Expect 脚本
Expect是一个免费的编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预。 Expect的作者Don Libes在1990年开始编写Expect时对Expect做有如下定义:Expect是一个用来实现自动交互功能的软件套件(Expect [is a] software suite for automating interactive tools)。使用它系统管理员的可以创建脚本用来实现对命令或程序提供输入,而这些命令和程序是期望从终端(terminal)得到输入,一般来说这些 输入都需要手工输入进行的。Expect则可以根据程序的提示模拟标准输入提供给程序需要的输入来实现交互程序执行。甚至可以实现实现简单的BBS聊天机 器人。 :)
Expect是不断发展的,随着时间的流逝,其功能越来越强大,已经成为系统管理员的的一个强大助手。Expect需要Tcl编程语言的支持,要在系统上运行Expect必须首先安装Tcl。
Expect工作原理 :
从最简单的层次来说,Expect的工作方式象一个通用化的Chat脚本工具。Chat脚本最早用于UUCP网络内,以用来实现计算机之间需要建立连接时进行特定的登录会话的自动化。
Chat脚本由一系列expect-send对组成:expect等待输出中输出特定的字符, 通常是一个提示符,然后发送特定的响应。例如下面的Chat脚本实现等待标准输出出现Login:字符串,然后发送somebody作为用户名;然后等待 Password:提示符,并发出响应sillyme。

The Expect Home Page1. 下载了expect.tar.gz;
2. 解压;
#tar zxvf expect.tar.gz
3. 安装;
#./configure
./configure
configuring Expect 5.43.0
checking for autoconf... yes
checking configure up to date... yes
checking host system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking target system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking build system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking shell to use within Make...
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for building with threads... no (default)
checking for Tcl configuration... configure: warning: Can't find Tcl configuration definitions
./configure: line 1106: #: No such file or directory

看来要找Tcl;
#whereis tcl
tcl: /usr/lib/tcl8.4 /usr/share/tcl8.4
改变tcl目录,重试;
#./configure --with-tcl=/usr/lib/
configuring Expect 5.43.0
checking for autoconf... yes
checking configure up to date... yes
checking host system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking target system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking build system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

checking shell to use within Make...
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for building with threads... no (default)
checking for Tcl configuration... configure: error: /usr/lib/ directory doesn't contain tclConfig.sh
看来要找tclConfig.sh;
# find / -name "tclConfig.sh"
什么都没有找到!看来要重新安装tcl;
进入The Expect Home Page,
跳转到tcl主页the Tcl Developer Xchange web site,
选择Tcl8.5, 进入http://www.tcl.tk/software/tcltk/8.5.html
点击Download Tcl/Tk 8.5.8 Source Releases,
选择下载tcl8.4.19-src.tar.gz,和tk8.4.19-src.tar.gz;

a. 编译安装tcl8.4.19;
#tar zxvf tcl8.4.19-src.tar.gz
#cd tcl8.4.19
#cd unix
#configure
最后几句:
... ...
updating cache ./config.cache
creating ./config.status
creating Makefile
creating dltest/Makefile
creating tclConfig.sh
#make
#make install
b. 编译安装tk8.4.19;
同样的步骤,不再详述;

回到断点,继续安装expect;
# ./configure
checking for sin... no
checking for Tcl private headers... checking for tclInt.h... no
configure: error: Can't find Tcl private headers

# find / -name "tclInt.h"
/home/guoq/osrc/tcl8.4.19/generic/tclInt.h

# ./configure --help
... ...
--with-tclinclude       directory where tcl private headers are
... ...

#./configure --with-tclinclude=/home/guoq/osrc/tcl8.4.19/generic/
... ...
checking for Tcl private headers... (cached) found in /home/guoq/osrc/tcl8.4.19/generic
updating cache .././config.cache
creating ./config.status
creating Makefile

看来ok了!
#make
#make install

4. 写个脚本试试;
#!/usr/local/bin/expect -f

set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30

spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]*"
interact

哇哈哈!I am in.

转载于:https://blog.51cto.com/myunix/1542343

expect 编译安装相关推荐

  1. 编译安装postfix+sasl+mysql+dovecot+extmail构建完成的邮件系统(一)

    编译安装postfix 在之前的文章我增提到过,目前linux常用的MTA软件有sendmail,qmail,exim,postfix.虽然目前使用最多的MTA是sendmail,但是sendmail ...

  2. 编译安装PCL点云库,Kinect2驱动,乐视Astra相机驱动

    编译安装PCL点云库 安装方法一 3d点云安装 apt-cache cearch pcl 安装 sudo apt install 上面查出来的 opencv不建议用以上方法因为需要 安装 opencv ...

  3. Centos7编译安装Xen环境(vtpm)

    编译xen环境(http://www.lvtao.net/server/574.html#comment-1882): yum update yum groupinstall "Develo ...

  4. 18、HTTP基本操作及源码编译安装 学习笔记

    HTTPHyper Text Transfer Protocol超文本传输协议 HTMLHyper Text Mark-up Language超文本标记语言 URIUniform Resource I ...

  5. Linux中级实战专题篇一:nginx服务(特性优势,yum安装,编译安装详解,虚拟主机技术详解)

    一.HTTP 介绍 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器 ...

  6. Ambari2.7整体编译+安装使用

    最近Ambari发布了新版本--v2.7.1,支持HDP_3.0.1版本,较Ambari2.6相比,最直观的感觉就是Web UI有了很大的改变,更加的美观:支持的hadoop相关组件,也是较新的版本: ...

  7. LAMP源码编译安装及一键部署LAMP架构

    文章目录 一.什么是LAMP? 1.LAMP平台概述 2.构建LAMP平台顺序 3.编译安装的优点 4.各组件的主要作用 二.LAMP架构流向 三.编译安装Apache服务 1.先关闭防火墙 2.将软 ...

  8. ansible-playbook编译安装nginx

    ansible-playbook编译安装nginx ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric) ...

  9. Expect的安装与应用,及实现自动检测另外一台服务器运行状态并重启,和使用expect脚本远程批量管理服务器与日志分析

    学习Expect Expect是什么? Expect是一个免费的编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预.  Expect是不断发展的,随着时间的流逝,其功能越来越强大,已经成为 ...

最新文章

  1. 上次谁说要简历模板来着?来!
  2. Autodesk Infrastructure Map Server 2014的开发文档在哪里?
  3. UTF-8和Unicode
  4. 让Web站点崩溃最常见的七大原因
  5. 【渝粤题库】陕西师范大学292969 会计学 作业 (专升本、高起本)
  6. 软件接口测试 (1)
  7. 漫步数学分析番外五(下)
  8. 下载部署和管理Windows Azure应用程序评估
  9. etc php5 conf.d,php – nginx:[emerg]“location”指令不允许在/etc/nginx/conf.d/default.conf中使用:...
  10. linux管道通信题目,操作系统实训(Linux)——习题解答、例题解析、实验指导-王红-实验实验7软中断及管道通信课案.ppt...
  11. 一行行地读取输入行,将把最长的行打印出来
  12. Beagle 0.2.16(附 Ubuntu Edgy 安顿源)
  13. FL Studio中钢琴卷帘窗的工具的使用
  14. 【语音播放】基于matlab GUI MP3设计【含Matlab源码 425期】
  15. django book 制作
  16. (四)JSP语法详细介绍--脚本元素
  17. A7芯片 IOS降级 跳过ID | ipad Mini2降级 10.3.3
  18. 有哪些免费批量删除PDF文档的页码的方法
  19. mkfs.ext3 快速格式化_求救!固态硬盘格式化不了!
  20. camera一些常见名词缩写

热门文章

  1. python:个性签名
  2. 洛谷:上学迟到(P5707)C语言
  3. 618口碑最好的运动蓝牙耳机,佩戴舒适蓝牙耳机推荐
  4. HR角度:优秀的简历应该是怎么样的?
  5. 计算机硬件有关的专业英语,计算机硬件专业英语词汇
  6. cyq.data mysql_CYQ.Data4.5.5下载-CYQ.Data数据框架整套下载4.5.5 免费版【附源码】-东坡下载...
  7. Hikari数据库连接池
  8. 乖宝宠物IPO过会:年营收25.75亿 KKR与君联是股东
  9. 使用阈值图修改角色脸部阴影
  10. 理光Ricoh Aficio 550 一体机驱动