Expect安装方法
第1步:使用root用户登录
第2步:复制安装文件
在合适的位置创建一个文件夹,例如soft
修改文件夹读写权限
chmod 777 soft
第3步:解压安装包
[我已经上传了expect-5.43.0.tar.gz 和 tcl8.4.11-src.tar.gz 在本文后面可以点击下载]
把expect-5.43.0.tar.gz和tcl8.4.11-src.tar.gz复制到soft目录下,
解压tcl8.4.11-src.tar.gz
tar –xvf tcl8.4.11-src.tar.gz
解压后将创建tcl8.4.11 文件夹
解压expect-5.43.0.tar.gz
tar –xvf expect-5.43.0.tar.gz
解压后将创建expect-5.43 文件夹
目录结构如下图(SSH登录的截图)所示:
上图中可以看出在/soft下有tcl8.4.11和tcl8.4.11 两个文件夹
第4步:安装tcl
进入/soft/tcl8.4.11/unix 目录
a.执行sed -i "s/relid'/relid/" configure
b.执行./configure --prefix=/expect
c.执行make
d.执行make install
e.执行mkdir -p /tools/lib
f.执行cp tclConfig.sh /tools/lib/
g. 将/tools/bin目录export到环境变量
tclpath=/tools/bin
export tclpath
第5步:安装Expect
进入/soft/expect-5.43目录
执行./configure --prefix=/tools --with-tcl=/tools/lib --with-x=no
如果最后一行提示:
configure: error: Can't find Tcl private headers
需要添加一个头文件目录参数
--with-tclinclude=../tcl8.4.11/generic,即
./configure --prefix=/tools --with-tcl=/tools/lib --with-x=no --with-tclinclude=../tcl8.4.11/generic
../tcl8.4.11/generic 就是tcl解压安装后的路径,一定确保该路径存在
执行make
执行make install
编译完成后会生在/tools/bin内生成expect命令
执行/tools/bin/expect出现expect1.1>提示符说明expect安装成功.
第6步:创建一个符号链接
ln -s /tools/bin/expect /usr/bin/expect
查看符号连接
ls -l /usr/bin/expect
lrwxrwxrwx 1 root root 17 06-09 11:38 /usr/bin/expect -> /tools/bin/expect
这个符号链接将在编写expect脚本文件时用到,例如在expect文件头部会指定用于执行该脚本的shell
#!/usr/bin/expect
...
...
----------------------
1.下载expect和tcl
下载地址:http://download.csdn.net/download/tobyaries/5754943
2.安装expect
tar -zxvf tcl8.4.11-src.tar.gz
tar -zxvf expect-5.43.0.tar.gz
cd tcl8.4.11/unix
./configure
make && make install
cd expect-5.43
./configure --with-tcl=/usr/local/lib/ --with-tclinclude=/data/software/tcl8.4.11
make && make install
3.脚本测试
- #!/usr/bin/expect -f
- set timeout 30
- set name [lindex $argv 0]
- set pw [lindex $argv 1]
- log_user 0
- spawn passwd $name
- for {set i 1} {$i < 3} {incr i} {
- expect "*password:" {send "$pw\r"}
- }
- expect "*successfully"
- send_user "Password updated successfully\n"
- expect eof
[解析]
很简单的程序,首先把第一个参数赋值给变量name作为用户名,把第二个参数赋值给pw作为密码。然后关闭标准输出,就是类似shell的 "> /dev/null",然后spawn开启子进程运行passwd程序,因为会重复输入2次密码,所以这里我们用到了TCL语法的for循环,执行2次密码输入。最后匹配到successfully字样的就输出修改成功,然后退出脚本。
Expect安装方法的更多相关文章
- Xamarin+Prism开发详解四:简单Mac OS 虚拟机安装方法与Visual Studio for Mac 初体验
Mac OS 虚拟机安装方法 最近把自己的电脑升级了一下SSD固态硬盘,总算是有容量安装Mac 虚拟机了!经过心碎的安装探索,尝试了国内外的各种安装方法,最后在youtube上找到了一个好方法. 简单 ...
- CocoaPods 的简单快速安装方法
CocoaPods 的简单快速安装方法(Setting up CocoaPods master repo 卡着不动,是因为淘宝镜像已经不能用了. 一.git clone方法安装cocoapods 镜像 ...
- windows下安装easy_install, pip 及whl文件安装方法
转:http://www.cnblogs.com/wu-wenmin/p/4250330.html 写在前面的话 最近在看"Computer Vision with Python" ...
- Laravel安装方法 (windows)
Laravel安装方法(windows) 安装PHP 下载PHP7 http://windows.php.net/download#php-7.0 进入上述网站下载PHP7 选择zip包解压安装 配置 ...
- linux tcl expect 安装(转)
linux tcl expect 安装 一.Tcl安装 1. 下载:tcl8.4.20-src.tar.gz http://www.tcl.tk/software/tcltk/downloadnow ...
- win8.1系统的安装方法详细图解教程
win8.1系统的安装方法详细图解教程 关于win8.1系统的安装其实很简单 但是有的童鞋还不回 所以今天就抽空做了个详细的图解教程, 安装win8.1系统最好用U盘安装,这样最方便简单 而且系统安装 ...
- ubuntu一些基本软件安装方法
ubuntu一些基本软件安装方法 首先说明一下 ubuntu 的软件安装大概有几种方式:1. deb 包的安装方式deb 是 debian 系 Linux 的包管理方式, ubuntu 是属于 deb ...
- Ehlib安装方法有窍门
Ehlib安装方法有窍门,如果不知道该安装方法,很难成功安装,Delphi 7(D5.D6也如此)中的安装方法 1.把EhLib中的common和DataService文件拷贝到Delph ...
- Ubuntu .deb包安装方法
使用apt-get方法安装的软件,所有下载的deb包都缓存到了/var/cache/apt/archives目录下了,所以可以把常用的deb包备份出来,甚至做成ISO工具包.刻盘,以后安装Ubuntu ...
随机推荐
- bistu新生-1004
#include "stdio.h"#include "stdlib.h"#include "math.h"int cmp(const vo ...
- 【LeetCode OJ】Word Ladder II
Problem Link: http://oj.leetcode.com/problems/word-ladder-ii/ Basically, this problem is same to Wor ...
- python numpy 的运算
一,基本运算 >>> a = array([1,2,3,4])>>> aarray([1, 2, 3, 4])>>> b=arange(4)> ...
- SSIS使用OleDB和Ado.Net两种方式调用 存储过程
在使用”执行 SQL 任务“组件调用存储过程时,连接方式使用OleDB和Ado.Net稍有不同,结合图例说明一下 当我们使用OleDB时,设置的截图如下: 参数使用?来代替,Parameter Nam ...
- Map/Reduce的类体系架构
Map/Reduce的类体系架构 Map/Reduce案例解析: 先以简单的WordCount例程, 来讲解如何去描述Map/Reduce任务. public static void main(Str ...
- Java 正则表达式学习总结和一些小例子
从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础工具,可以用于很多类型的文本处理, 如匹配,搜索,提取和分析结构化内容. java.util.r ...
- Codeforces Round #366 (Div. 2) B 猜
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- iPhone 6/iPhone 6 Plus硬件性能
iPhone 6/iPhone 6 Plus硬件性能 评分 4 分 正 如之前传闻的,这次同时发布了两款iPhone产品,分别是4.7英寸的iPhone 6和5.5英寸的iPhone 6 Plus.苹 ...
- smartUpload组件文件上传
public class SmartUploadServlet extends HttpServlet { public void doGet(HttpServletRequest request, ...
- C#部分---arraylist集合、arraylist集合中的object数据转换成int类string类等;间隔时间的表示方法;
ArrayList和Array的区别: 相同点:1.两者都实现了IList.ICollection.IEnumerable接口: 2.两者都可以使用证书索引访问集合中的元素,包括读取和赋值 ...