非root用户安装expect
看了很多教程,踩了很多坑,分享给需要的人
准备
-
- 其实不用root权限的原理很简单,那就是把文件安装到
home/用户
工作目录下:修改–prefix,调用的时候直接调用home/用户
目录的文件
- 其实不用root权限的原理很简单,那就是把文件安装到
-
expect是对TCL(tool command language)的扩充,所以需要先安装tcl
-
检查是否有tcl和expect
~$ whereis tcl ~$ whereis expect
-
查看操作系统位数
~$ cat /proc/version Linux version 5.4.0-91-generic (buildd@lgw01-amd64-024) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #102~18.04.1-Ubuntu SMP Thu Nov 11 14:46:36 UTC 2021
tcl安装
-
创建tcl目录,然后下载源码包
~$ cd tcl # 下载tcl 8.4.11 ~/tcl$ wget http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz # 解压 ~/tcl$ tar xzvf tcl8.4.11-src.tar.gz # 进入刚刚解压的 /home/user/tcl/tcl8.4.19/unix 目录 ~/tcl$ cd tcl8.4.11/unix/ ~/tcl/tcl8.4.11/unix$ ./configure --prefix=$HOME/tcl --enable-shared #prefix是安装目录; $HOME代表/home/user; ‘./’是编译操作,用于得到makefile; ebavke-shared是开启共享,其他内置包可以使用 checking system version (for dynamic loading)... ./configure: 1: ./configure: Syntax error: Unterminated quoted string
-
这里的./configure会报错,8.4.13后的安装包就没有了 这里引用自大佬的踩坑史,直接复制了
#看提示好像是configure出了问题,于是我就上网去搜了,没有打开cnfigure看:) #得到的结果说是configure里的引号配对错误引起的,搜了关键字 system,找到了一看,还真是: 2133 system=MP-RAS-`awk '{print }' /etc/.relid'` #处理方式是去掉倒数第2个那个多出来的下引号,改为: 7611 system=MP-RAS-`awk '{print }' /etc/.relid` #多了一个下引号,本以为去掉之后可以直接执行完,没想到又有一个错误: checking FIONBIO vs. O_NONBLOCK for nonblocking I/O... ./configure: 1: ./configure: Syntax error: Unterminated quoted string #这回就有经验了,十有八九还是configure的问题啊,于是又搜FIONBIO,结果有找到了一处 7611 system=MP-RAS-`awk '{print }' /etc/.relid‘` #处理方式依旧是去掉多出来下引号,改为: 7611 system=MP-RAS-`awk '{print }' /etc/.relid` #然后再重新configure就可以了。
-
执行源码安装命令
~/tcl/tcl8.4.11/unix$ make ~/tcl/tcl8.4.11/unix$ make install #安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h 拷贝到子目录generic中。暂时不要删除tcl源代码,因为expect的安装过程还需要用。 ~/tcl/tcl8.4.11$ cp unix/tclUnixPort.h generic/
expect安装
-
创建tcl目录,把源码包搞到服务器上
~$ cd expect # 解压 ~/expect$ tar xzvf expect5.45.tar.gz # 进入解压目录 ~/expect$ cd expect5.45/ ~/expect/expect5.45$ ./configure --prefix=$HOME/expect --with-tcl=$HOME/tcl/lib --with-tclinclude=/home/user/tcl/tcl8.4.11/generic #--with-tcl:指定tcl相关的路径,为了找到tclConfig.sh文件; --prefix:指定expect的安装路径 # 安装 ~/expect/expect5.45$ make ~/expect/expect5.45$ make install
-
这个时候expect已经成功安装好了,可以在
/home/user/tcl/bin
中看到 -
注意
/home/user/expect/bin
目录下是没有expect文件的,所以在.sh文件中使用expect的时候,第一行需要指定\#!/home/user/tcl/bin/expect
。 -
当然,这个问题可以通过设置软链接(我理解为window中的快捷方式)解决。这样就会在
/home/user/expect/bin/
目录下创建expect文件,在.sh文件中使用expect的时候,第一行可以指定\#!/home/user/expect/bin/expect
# ln的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln -s 源文件 目标文件 ~$ ln -s /home/user/tcl/bin/expect /home/user/expect/bin/expect # 通过以下命令查看软链接情况 ~$ ls -l /home/user/expect/bin/expect lrwxrwxrwx 1 user 27 1月 13 22:40 /home/user/expect/bin/expect -> /home/user/tcl/bin/expect # 这个符号链接将在编写expect脚本文件时用到,例如在expect文件头部会指定用于执行该脚本的shell
怎么卸载
-
首先要明确使用./configure方式属于通过源码安装,所以要卸载有两个办法
- Linux 下configure 参数配置与软件的安装与卸载 - 全栈编程 - 博客园 (cnblogs.com)
- 怎么卸载用 make install 编译安装的软件? - 知乎 (zhihu.com)
- 作者良心,在执行makefile的时候,会在makefile告知uninstall步骤,或者有uninstall命令->
make uninstall
即可 - 作者不良心,
make uninstall
无效,那就只能把安装出来的文件手动删除
-
所以说设置–prefix非常重要!!!!!!它代表安装目录