由于expect需要依赖包tcl,去http://www.tcl.tk/software/tcltk/downloadnow84.html进行下载。
然后下载expect:http://sourceforge.net/projects/expect/?source=dlp
首先解压tcl,
unzip tcl860-src.zip
,然后通过./configure && make && make install进行安装。
然后解压expect:
通过如下命令进行配置
./configure --with-tcl=/usr/local/lib --with-tclinclude=/usr/local/expect5.45/tcl8.6.0/generic
最后通过make && make install进行安装,注意--with-tcl为tcl安装的lib目录,--with-tclinclude路径为你解压后的tcl里的generic目录。
以下是远程ssh执行脚本和scp的函数
auto_ssh () {
expect -c "set timeout -1;
spawn ssh -o StrictHostKeyChecking=no $2 ${@:3};
expect {
*assword:* {send -- $1\r;
expect {
*denied* {exit 2;}
eof
}
}
eof {exit 1;}
}
"
return $?
}
auto_scp () {
expect -c "set timeout -1;
spawn scp -r -o StrictHostKeyChecking=no ${@:2};
expect {
*yes/no* {send yes\r}
*assword:* {send -- $1\r;
expect {
*denied* {exit 1;}
eof
}
}
eof {exit 1;}
}
"
return $?
}
将输出内容附加到日志文件并同步打印输出的方式
# ls -l | tee -a ./t.log
# make image | tee -a make_image.log
另外如果安装tcl提示如下错误,需要安装gcc
[root@oadev unix]# ./configure
checking whether to use symlinks for manpages... no
checking whether to compress the manpages... no
checking whether to add a package name suffix for the manpages... no
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
通过 yum -y install gcc进行在线安装即可。
[root@oadev local]# yum -y install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: mirrors.yun-idc.com
* extras: mirrors.btte.net
* rpmforge: ftp.riken.jp
* updates: mirror.bit.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package gcc.i386 0:4.1.2-54.el5 set to be updated
--> Processing Dependency: cpp = 4.1.2-54.el5 for package: gcc
--> Processing Dependency: libgomp >= 4.1.2-54.el5 for package: gcc
--> Processing Dependency: libgcc >= 4.1.2-54.el5 for package: gcc
--> Running transaction check
---> Package cpp.i386 0:4.1.2-54.el5 set to be updated
---> Package libgcc.i386 0:4.1.2-54.el5 set to be updated
---> Package libgomp.i386 0:4.4.7-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
gcc i386 4.1.2-54.el5 base 5.2 M
Installing for dependencies:
libgomp i386 4.4.7-1.el5 base 74 k
Updating for dependencies:
cpp i386 4.1.2-54.el5 base 2.7 M
libgcc i386 4.1.2-54.el5 base 97 k
Transaction Summary
====================================================================================================================================
Install 2 Package(s)
Upgrade 2 Package(s)
Total download size: 8.0 M
Downloading Packages:
(1/4): libgomp-4.4.7-1.el5.i386.rpm | 74 kB 00:00
(2/4): libgcc-4.1.2-54.el5.i386.rpm | 97 kB 00:00
(3/4): cpp-4.1.2-54.el5.i386.rpm | 2.7 MB 00:10
(4/4): gcc-4.1.2-54.el5.i386.rpm | 5.2 MB 00:09
------------------------------------------------------------------------------------------------------------------------------------
Total 225 kB/s | 8.0 MB 00:36
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : libgcc 1/6
Updating : cpp 2/6
Installing : libgomp 3/6
Installing : gcc 4/6
Cleanup : cpp 5/6
Cleanup : libgcc 6/6
Installed:
gcc.i386 0:4.1.2-54.el5
Dependency Installed:
libgomp.i386 0:4.4.7-1.el5
Dependency Updated:
cpp.i386 0:4.1.2-54.el5 libgcc.i386 0:4.1.2-54.el5
Complete!
以下为http://blog.csdn.net/wind19/article/details/4905453转载
===============================================
我试验的环境是SuSe Linux 10.1
expect的主页:http://expect.nist.gov/
最新稳定版5.43.0的下载地址:http://expect.nist.gov/expect.tar.gz
expect依赖于tcl/tk,因此在安装expect之前先安装tcl/tk。
tcl/tk8.4.16的下载面页:
http://www.tcl.tk/software/tcltk/downloadnow84.html
软件包的下载地址:
http://prdownloads.sourceforge.net/tcl/tcl8.4.16-src.tar.gz
http://prdownloads.sourceforge.net/tcl/tk8.4.16-src.tar.gz
检查系统,看tcl是否已经安装。
[root@rhel ~]# rpm -qa|grep tcl
已经安装的情况:
因为expect需要重新编译后安装,那么就需要tcl的开发包。
rpm -ivh --force tcl-devel-8.4.13-3.fc6.i386.rpm
然后将expect-5.43包解开,开始读INSTALL文档,系统管理员告诉我,不用读,直接运行 ./configure --help开参数。确实好使,又土了一次 :-( 。
1.首先确定tcl开发包安装的位置
rpm -qpl tcl-devel-8.4.13-3.fc6.i386.rpm|more
2.然后根据参数,运行./configure
./configure --with-tcl=/usr/lib --with-tclinclude=/usr/include/tcl-private/generic
3.执行
make
4.执行
make install
完成第四步后,expect顺利安装成功。 -
没有安装的情况:
第一步,安装tcl
[root@supersun.biz download]#cd tcl8.4.16/unix/
./configure
make
make install
安装之后不要删除源码包,在安装expect时需要tcl的头文件。
安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h copy到子目录generic中
第二步,安装tk
[root@supersun.biz download]#cd tk8.4.16/unix/
./configure
make
make install
第三步,安装expect
在不提供参数的情况下执行configure报错:
checking for Tcl private headers... checking for tclInt.h... no
configure: error: Can't find Tcl private headers
再次运行configure脚本,并指定tcl的头文件所在目录:
[root@supersun.biz expect-5.43]#./configure --with-tclinclude=../tcl8.4.16/generic
脚本运行正常,进行执行make进行编译
make
如果make,或是configure有错误的话,根据提示,再增加配置参数
编译过程中未出现错误,执行安装:
make install
配置参数的意思是:
·--with-tcl=/usr/tcl/lib:(我的环境中是/usr/local/lib) 确保配置脚本找到临时工具目录中的Tcl,我们不希望它使用主系统中可能存在的tcl.
·--with-x=no: 告诉配置脚本,不要查找 Tk (Tcl 的 GUI 组件) 或 X 窗口系统库,这两个都有可能存在于主系统中。
·-with-tclinclude:帮助脚本找到所需要的tcl头文件。