Expect软件主要用于提供人机交互功能。
在写shell script脚本过程中,常常遇到 su、scp、ssh等需要输入密码验证的命令时,可以利用expect输入密码信息,从而免去手动验证的麻烦。
下面提供安装expect软件的方法。
expect相关开源软件下载路径:
http://download.csdn.net/detail/hanlizhong85/9886259
linux安装expect,需要先安装依赖包tcl、tk。
通过rpm -qa查询是否已安装相关软件包:
rpm -qa | grep -E 'tcl|tk|expect'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、tcl安装(tcl8.5.9-src.tar.gz )
cd /tmp
tar -zxvf tcl8.5.9-src.tar.gz
cd tcl8.5.9/unix/
./configure --prefix=/usr/local/tcl/ --enable-shared
make
make install
/usr/local/tcl/bin/tclsh8.5 ---验证安装成功与否
%exit
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2、tk安装(tk8.5.9-src.tar.gz)
cd /tmp
tar -zxvf tk8.5.9-src.tar.gz
cd tk8.5.9/unix/
./configure --prefix=/usr/local/tk/ --with-tcl=/usr/local/tcl/lib/ --enable-shared
make
make install
ln -s /usr/local/tcl/lib/libtcl8.5.so /usr/local/tk/lib/libtcl8.5.so
/usr/local/tk/bin/wish8.5
%exit
注意:若执行/usr/local/tcl/bin/tclsh8.5 时,报 Applicationinitialization failed: no display name and no $DISPLAY environment variable 错误,则需要先执行 exportPATH=$PATH:/usr/local/tcl/bin 添加环境变量来解决。当然,这种方法只能保证本次生效,为保证永久有效,可以把 export PATH=$PATH:/usr/local/tcl/bin 写入 /etc/profile 中。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3、expect安装(expect-5.44.1.15.tar.gz)
cd /tmp
tar -zxvf expect-5.44.1.15.tar.gz
cd expect-5.44.1.15
./configure --prefix=/usr/local/expect/ --with-tcl=/usr/local/tcl/lib/ --with-tclinclude=/tmp/tcl8.5.9/generic/ --with-tk=/usr/local/tk/lib/ --with-tkinclude=/tmp/tk8.5.9/generic/ --enable-shared
make
make install
expect
expect1.1> exit
完成安装,即可执行expect脚本了!!
注意:上面的三处 /tmp 是expect-5.44.1.15.tar.gz及其依赖的开源软件包所在目录,若你存放在其他目录下,需要做相应地修改。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++