linux安装expect
发布日期:2021-04-30 21:02:53 浏览次数:120 分类:精选文章

本文共 951 字,大约阅读时间需要 3 分钟。

前言

Expect是在TCL(Tool Command Language 工具脚本语言,是Linux内的一种语言包)基础上创建起来的。安装expect时必须先安装tcl。

下载源码包

tcl8.4.11-src.tar.gz

wget http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz

expect5.45.tar.gz

wget http://download.chinaunix.net/down.php?id=5288&ResourceID=2845&site=1

安装tcl8.4.11

3.1 解压

tar xvf tcl8.4.11-src.tar.gz

3.2 安装配置

cd tcl8.4.11/unix ./configure --prefix=/usr/tcl --enable-sharedmake make install

安装 expect5.45

4.1 解压

tar xvf expect5.45.tar.gz

4.2 安装配置

cd expect5.45 ./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/generic/make

执行脚本

案例: 作用:远程登录删除目录下文件

#!/usr/tcl/bin/expect -f for {set i 14} {$i < 23} {incr i} {     spawn ssh root@192.168.4.$i     expect {        "*password:*" {        send "123456\r"        exp_continue            }        "*yes/no)?*" {        send "yes\r"        exp_continue        }    }    expect "]# "    send "rm -rf /usr//work/*\r"    send "exit\r"    expect eof
上一篇:蓝桥杯算法练习笔记(4)__枚举
下一篇:ShardingShpere分库分表4-ShardingProxy分库分表实战及同类产品选型对比

发表评论

最新留言

不错!
[***.144.177.141]2026年06月01日 04时18分08秒