【Linux学习】expect使用

1. 安装(centos版本)

tcl&&expect安装
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

wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download(https://sourceforge.net/projects/expect/)
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
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect

如果wget下载很慢或者下载不下来,可以直接去网址上下好再上传到服务器上
安装过程中如果检测到无c等编译工具,可以使用【yum install gcc gcc-c++ gcc-g77】进行安装

2. 使用


首先表明解释器为安装路径下的#!/usr/expect/bin/expect
expect使用的最后需要给interact指令(个人理解是登录脚本命令内容执行交互完成之后再退出执行交互进程)

原文地址:https://www.cnblogs.com/ricebug2/p/14606399.html