linux下expect环境安装以及简单脚本测试
网上的原贴:
expect是交互性很强的脚本语言,可以帮助运维人员实现批量管理成千上百台服务器操作,很实用!
expect依赖于tcl,而linux系统里一般不自带安装tcl,所以需要手动安装
下载:expect-5.43.0.tar和tcl8.4.11-src.tar
下载地址:https://pan.baidu.com/s/1kVyeLt9
提取密码:af9p
安装前提:需要安装gcc,可以参考:
redhat 5.1安装gcc.docx;
将expect和tcl的软件包下载放到/usr/local/src目录下
(1)解压tcl,进入tcl解压目录,然后进入unix目录进行编译安装
[root@xw4 src]# tar -zvxf tcl8.4.11-src.tar.gz
[root@xw4 src]# cd tcl8.4.11/unix
[root@xw4 unix]# ./configure
[root@xw4 unix]# make && make
(2)安装expect
[root@xw4 src]# tar -zvxf expect-5.43.0.tar.gz
[root@xw4 src]# cd expect-5.43.0
[root@xw4 expect-5.43.0]# ./configure --with-tclinclude=/usr/local/src/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/
[root@xw4 expect-5.43.0]# make && make install
(3)安装完成后进行测试
[root@xw4 ~]# expect
expect1.1>
expect1.1>
实验结果:
安装1中,
[root@xw4 unix]# ./configure
有报错:
checking system version (for dynamic loading)... ./configure: line 7624: syntax error near unexpected token `)'
./configure: line 7624: ` OSF*)'
然后执行下一步:
[root@localhost unix]# make && make
make: *** No targets specified and no makefile found. Stop
原因,是由于tcl8.4.11-src.tar的问题,检查本机的linux版本参数:
[root@localhost ~]# cat /proc/version
Linux version 2.6.18-53.el5xen ([email protected]) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Wed Oct 10 17:06:12 EDT 2007
换成tcl8.4.19-src.tar.gz解决;
安装2中执行:
[root@xw4 expect-5.43.0]# ./configure --with-tclinclude=/usr/local/src/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/
出错:
checking for Tcl configuration... configure: error: /usr/lib/ directory doesn't contain tclConfig.sh
原因:
tclConfig.sh的位置错误,
[root@localhost ~]# find / -name "tclConfig.sh"
/usr/local/src/tcl8.4.19/unix/tclConfig.sh
修改命令后执行:
./configure --with-tclinclude=/usr/local/src/tcl8.4.19/generic --with-tclconfig=/usr/local/src/tcl8.4.19/unix/
运行成功!
下面为网盘中的安装文档及所依赖的安装包:
http://pan.baidu.com/s/1qYLFZkC