expect 介绍
expect是一种脚本语言,它能够代替人工实现与终端的交互,主要应用于执行命令和程序时,系统以交互形式要求输入指定字符串,实现交互通信。
使用场景:
(1)并根据预定标准回答其问题,回答“是”、“否”或将控制权交还给您
(2)远程连接设备并执行自动化操作
(3)主要是一些需要人机交互的地方,如果提前知道应该输入什么指令都可以使用expect 工具
更换阿里镜像源
在/etc/apt/目录下有一个sources.list 文件夹,默认是官方的镜像,是在国外的服务器!所有软件的下载速度会非常慢,甚至无法下载!所以需要更换镜像源,步骤如下:
1.将原本的sources.list 拷贝一份为 sources.list.bak
cp sources.list sources.list.bak
2.打开source.list,修改为阿里镜像源
vi sources.list
3.按一下 ESC 键,确保退出编辑模式,按一下“:”键,然后输入“%d”,就可以删除所有内容了,% 表示文件中的所有行
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
4.更新镜像源
apt-get update
安装gcc
sudo apt-get build-dep gcc
没有安装gcc的话编译的时候会报错
安装make
apt-get install make
查看是否安装成功:make -v
下载 tcl 和 expect
cd /usr/local/src/
wget http://sourceforge.net/projects/tcl/files/Tcl/8.4.19/tcl8.4.19-src.tar.gz
sudo tar -zxvf tcl8.4.19-src.tar.gz
wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz
sudo tar -zxvf expect5.45.tar.gz
安装 tcl
cd tcl8.4.19/unix/
sudo ./configure
sudo make
sudo make install
安装 expect
cd expect5.45/
sudo ./configure --with-tclinclude=/usr/local/src/tcl8.4.19/generic/ --with-tclconfig=/usr/local/lib/
sudo make
sudo make install
测试