一、概述
我们通过Shell可以实现简单的控制流功能,如:循环、判断等。但是对于需要交互的场合则必须通过人工来干预,有时候我们可能会需要实现和交互程序如telnet服务器等进行交互的功能。而expect就使用来实现这种功能的工具。
expect是一个免费的编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预。expect是不断发展的,随着时间的流逝,其功能越来越强大,已经成为系统管理员的的一个强大助手。expect需要Tcl编程语言的支持,要在系统上运行expect必须首先安装Tcl。
二、expect的安装
expect是在Tcl基础上创建起来的,所以在安装expect前我们应该先安装Tcl。
(一)Tcl 安装
主页: http://www.tcl.tk
下载地址: http://www.tcl.tk/software/tc...
1.下载源码包
wget http://nchc.dl.sourceforge.ne...
2.解压缩源码包
tar xfvz tcl8.4.11-src.tar.gz
3.安装配置
cd tcl8.4.11/unix
./configure --prefix=/usr/tcl --enable-shared
make
make install
cp tclUnixPort.h ../generic/
注意:
1、安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h copy到子目录generic中。
2、暂时不要删除tcl源代码,因为expect的安装过程还需要用。
(二)expect 安装 (需Tcl的库)
主页: http://expect.nist.gov/
1.下载源码包
wget http://sourceforge.net/projec... --no-check-certificate
2.解压缩源码包
tar xzvf expect5.45.tar.gz
3.安装配置
cd expect5.45
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/generic
make
make install
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect
使用脚本一键安装(源码)
name installExp.sh
mkdir -p expect && cd expect
[[ ! -e tcl8.4.11-src.tar.gz ]] && wget http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz
tar xfvz tcl8.4.11-src.tar.gz
cd tcl8.4.11/unix
./configure --prefix=/usr/tcl --enable-shared
make
make install
\cp tclUnixPort.h ../generic/
cd ../../
[[ ! -e expect5.45.tar.gz ]] && wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz --no-check-certificate
tar xzvf expect5.45.tar.gz
cd expect5.45
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/generic
make
make install
if [ ! -e /usr/expect/bin/expect ];then
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect
fi
epxnum=$(cat /etc/profile| grep /usr/expect/bin | wc -l)
if [ ${epxnum} -eq 0 ];then
cat>> /etc/profile <<EOF
export PATH=\$PATH:/usr/expect/bin/
EOF
source /etc/profile
fi
cd ../
执行source installExp.sh
即可
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。