• Linux绿色版软件expect


    Linux中因为种种原因不允许安装软件,那么就是说只能用解压即可使用的那种。

    这次以expect(自动应答)软件为例。

    0x00:安装

    [root@node1 ~]# yum install -y expect
    已加载插件:fastestmirror, priorities, product-id, search-disabled-repos, subscription-manager
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    =====
    中间略
    
    =====
    
    依赖关系解决
    
    ===================================================================================================================
     Package                 架构                    版本                              源                         大小
    ===================================================================================================================
    正在安装:
     expect                  x86_64                  5.45-14.el7_1                     c7-media                  262 k
    为依赖而安装:
     tcl                     x86_64                  1:8.5.13-8.el7                    c7-media                  1.9 M
    
    事务概要
    ===================================================================================================================
    安装  1 软件包 (+1 依赖软件包)
    
    总下载量:2.1 M
    安装大小:4.9 M
    Downloading packages:
    -------------------------------------------------------------------------------------------------------------------
    总计                                                                               2.8 MB/s | 2.1 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在安装    : 1:tcl-8.5.13-8.el7.x86_64                                                                      1/2 
      正在安装    : expect-5.45-14.el7_1.x86_64                                                                    2/2 
      验证中      : 1:tcl-8.5.13-8.el7.x86_64                                                                      1/2 
      验证中      : expect-5.45-14.el7_1.x86_64                                                                    2/2 
    
    已安装:
      expect.x86_64 0:5.45-14.el7_1                                                                                    
    
    作为依赖被安装:
      tcl.x86_64 1:8.5.13-8.el7                                                                                        
    
    完毕!

      通过上面安装信息知道,安装expect 还有个tcl的依赖,总共装了两个包。

    0x01:获取expect文件安装的路径

    [root@node1 ~]# whereis expect
    expect: /usr/bin/expect /usr/share/man/man1/expect.1.gz
    /usr/bin/expect  #这个就是expect可执行文件的路径,这个文件我们保留要用到
    /usr/share/man/man1/expect.1.gz  #expect帮助文件

    0x02:查看expect是否需要so动态库文件(相当于windows下dll文件)

    [root@node2 ~]# ldd /usr/bin/expect
            linux-vdso.so.1 =>  (0x00007fff35707000)
            libexpect5.45.so => /lib64/libexpect5.45.so (0x00007ffb1017f000)
            libtcl8.5.so => /lib64/libtcl8.5.so (0x00007ffb0fe57000)
            libdl.so.2 => /lib64/libdl.so.2 (0x00007ffb0fc53000)
            libm.so.6 => /lib64/libm.so.6 (0x00007ffb0f951000)
            libc.so.6 => /lib64/libc.so.6 (0x00007ffb0f583000)
            libutil.so.1 => /lib64/libutil.so.1 (0x00007ffb0f380000)
            libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ffb0f164000)
            /lib64/ld-linux-x86-64.so.2 (0x00007ffb103b3000)
    

      注意 “=>” 后面带路径/lib64/的so文件,是expect运行需要的,要全部复制。

    0x03:新建存放expect文件和so文件的目录

    [root@node2 ~]# mkdir expect   # 新建存放expect文件和so的目录
    [root@node2 ~]# cd expect
    [root@node2 expect]# pwd
    /root/expect
    [root@node2 expect]# ll  # 把上面找到的so文件都放进来
    总用量 4824
    -rw-r--r--. 1 root root   11352 6月  24 2015 expect
    -rw-r--r--. 1 root root 2156240 4月   1 2020 libc.so.6
    -rw-r--r--. 1 root root   19248 4月   1 2020 libdl.so.2
    -rw-r--r--. 1 root root  200848 6月  24 2015 libexpect5.45.so
    -rw-r--r--. 1 root root 1136944 4月   1 2020 libm.so.6
    -rw-r--r--. 1 root root  142144 4月   1 2020 libpthread.so.0
    -rw-r--r--. 1 root root 1242080 11月 20 2015 libtcl8.5.so
    -rw-r--r--. 1 root root   14424 4月   1 2020 libutil.so.1
    
    

    0x04:运行提示权限不足

    [root@node2 expect]# ./expect 
    -bash: ./expect: 权限不够
    

    0x05:赋权

    [root@node2 expect]# chmod 755 expect
    [root@node2 expect]# ll
    总用量 4824
    -rwxr-xr-x. 1 root root   11352 6月  24 2015 expect
    -rw-r--r--. 1 root root 2156240 4月   1 2020 libc.so.6
    -rw-r--r--. 1 root root   19248 4月   1 2020 libdl.so.2
    -rw-r--r--. 1 root root  200848 6月  24 2015 libexpect5.45.so
    -rw-r--r--. 1 root root 1136944 4月   1 2020 libm.so.6
    -rw-r--r--. 1 root root  142144 4月   1 2020 libpthread.so.0
    -rw-r--r--. 1 root root 1242080 11月 20 2015 libtcl8.5.so
    -rw-r--r--. 1 root root   14424 4月   1 2020 libutil.so.1
    

     

    0x06:加载当前路径下的so文件,而不是先去搜索系统路径的(这个正好是和Windows相反)

    [root@node2 expect]# export LD_LIBRARY_PATH=./
    

      注意:退出后即失效。永久生效查看另外一篇文章 -->   Ubuntu linux设置从当前目录下加载动态库so文件

     

    0x07:执行提示缺少tcl文件

    [root@node2 expect]# ./expect 
    Tcl_Init failed: Can't find a usable init.tcl in the following directories: 
        /usr/share/tcl8.5 /root/lib/tcl8.5 /lib/tcl8.5 /root/library /library /tcl8.5.13/library /tcl8.5.13/library
    
    This probably means that Tcl wasn't installed properly.
    

      按照提示,tcl所在的目录是/usr/share/tcl8.5 /root/lib/tcl8.5 /lib/tcl8.5 /root/library /library /tcl8.5.13/library /tcl8.5.13/library其中一个,越靠左的优先级最高,先找/usr/share/tcl8.5

    0x08:查看tcl目录内容

    [root@node1 ~]# ll -d /usr/share/tcl8.5
    drwxr-xr-x. 6 root root 249 9月   2 22:17 /usr/share/tcl8.5
    [root@node1 ~]# ll /usr/share/tcl8.5/
    总用量 308
    -rw-r--r--. 1 root root  20510 11月 20 2015 auto.tcl
    -rw-r--r--. 1 root root 130269 11月 20 2015 clock.tcl
    drwxr-xr-x. 2 root root   4096 9月   2 22:17 encoding
    -rw-r--r--. 1 root root   8965 11月 20 2015 history.tcl
    drwxr-xr-x. 2 root root     42 9月   2 22:17 http1.0
    -rw-r--r--. 1 root root  24848 11月 20 2015 init.tcl
    drwxr-xr-x. 2 root root   4096 9月   2 22:17 msgs
    drwxr-xr-x. 2 root root     46 9月   2 22:17 opt0.4
    -rw-r--r--. 1 root root  23588 11月 20 2015 package.tcl
    -rw-r--r--. 1 root root    803 11月 20 2015 parray.tcl
    -rw-r--r--. 1 root root  33170 11月 20 2015 safe.tcl
    -rw-r--r--. 1 root root   6693 11月 20 2015 tclDTrace.d
    -rw-r--r--. 1 root root   6379 11月 20 2015 tclIndex
    -rw-r--r--. 1 root root  11432 11月 20 2015 tm.tcl
    -rw-r--r--. 1 root root   4659 11月 20 2015 word.tcl
    

    0x09:里面有很多文件,所以直接打包tcl8.5这个文件夹

    [root@node1 ~]#  cd /usr/share/
    [root@node1 share]# tar -cf tcl.tar tcl8.5/
    

      

    0x0A:解压位置,上面运行expect时提示搜索的那几个路径,都可以放,这里放到/root/lib/tcl8.5/

    [root@node1 ~]#  mkdir lib
    [root@node1 ~]#  tar -xf tcl.tar lib/
    

    0x0B:因为expect只搜索这几个路径,如果lib文件夹想放到其他位置,用ln -s做个软连接即可

    [root@node2 expect]# ln -s /root/expect/lib ~/lib
    [root@node2 expect]# ll ~
    lrwxrwxrwx. 1 root root   16 9月   2 22:29 lib -> /root/expect/lib
    

    0x0C:再次运行expect,查看其版本

    [root@node2 expect]# pwd
    /root/expect
    
    [root@node2 expect]# ./expect -version
    expect version 5.45
    

      好了,成功运行。

      

    参考:

    Ubuntu linux设置从当前目录下加载动态库so文件

    ldd命令

    https://blog.csdn.net/daixiangzi/article/details/84346523/

    搜索linux加载当前目录so文件

  • 相关阅读:
    Facebook的体系结构分析---外文转载
    简易的IOS位置定位服务
    【简易版】IOS仿periscope自制狂赞飘桃心
    The Linux Programming Interface
    freeswitch嵌入lua脚本
    Epoll Tutorial – epoll In 3 Easy Steps!
    基于freeswitch的webrtc与sip终端呼叫
    buildroot添加第三方库
    rfc
    TCP/UDP Server-Client implementation in C
  • 原文地址:https://www.cnblogs.com/wutou/p/15216893.html
Copyright © 2020-2023  润新知