一、概述我们可以通过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.下载源码包wgethttp://nchc.dl.sourceforge.ne...2.解压源码包tarxfvztcl8.4.11-src.tar.gz3.安装配置cdtcl8.4.11/unix./configure--prefix=/usr/tcl--enable-sharedmakemakeinstallcptclUnixPort.h../generic/注意:1、安装完成后,进入tcl源码根目录,将unix子目录下的tclUnixPort.h复制到generic子目录下。2、暂时不要删除tcl源码,因为expect安装过程还是要用到的。(2)Expect安装(需要Tcl库)主页:http://expect.nist.gov/1。下载源码包wgethttp://sourceforge.net/projec...--no-check-certificate2。解决方案压缩源码包tarxzvfexpect5.45.tar.gz3.安装配置cdexpect5.45./configure--prefix=/usr/expect--with-tcl=/usr/tcl/lib--with-tclinclude=。./tcl8.4.11/genericmakemakeinstallln-s/usr/tcl/bin/expect/usr/expect/bin/expect使用脚本一键安装(源码)nameinstallExp.shmkdir-pexpect&&cdexpect[[!-etcl8.4.11-src.tar.gz]]&&wgethttp://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gztarxfvztcl8.4.11-src.tar。gzcdtcl8.4.11/unix./configure--prefix=/usr/tcl--enable-sharedmakemakeinstall\cptclUnixPort.h../generic/cd../../[[!-eexpect5.45.tar.gz]]&&wgethttp://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz--no-check-certificatetarxzvfexpect5.45。tar.gzcdexpect5.45./configure--prefix=/usr/expect--with-tcl=/usr/tcl/lib--with-tclinclude=../tcl8.4.11/genericmakemake安装如果[!-e/usr/expect/bin/expect];thenln-s/usr/tcl/bin/expect/usr/expect/bin/expectfiepxnum=$(cat/etc/profile|grep/usr/expect/bin|wc-l)if[${epxnum}-eq0];thencat>>/etc/profile<
