当前位置:网站首页>expect+sh实现自动交互
expect+sh实现自动交互
2022-07-25 09:22:00 【繁星¹⁸⁹⁵】
1. sh命令
2. expect命令
2.1 安装expect
sudo apt-get install expect
3. 实战
3.1 expect+sh实现批量自动创建用户
#!/bin/bash
#!/user/bin/expect
passwd=Fight666
list="username1 username2"
addgroup groupname1
for i in $list;
do
expect << EOF set timeout 10 spawn adduser $i expect "*password:" { send "$passwd\r"} expect "*password:" { send "$passwd\r"} expect "]:" { send "\r" } expect "]:" { send "\r" } expect "]:" { send "\r" } expect "]:" { send "\r" } expect "]:" { send "\r" } expect "*Y/n]" { send "y\r" } EOF
usermod -s /bin/bash -g groupname1 $i;
done
边栏推荐
猜你喜欢

学习 Redis linux 安装Redis

OC--包装类和处理对象

Flex layout syntax and use cases

初识Opencv4.X----方框滤波

Assignment 7.21 Joseph Ring problem and decimal conversion

【降维打击】希尔伯特曲线

【代码源】每日一题 国家铁路

The jar package has been launched on Alibaba cloud server and the security group has been opened, but postman still can't run. What should we do

Prim 最小生成树(图解)

【代码源】每日一题 - 排队
随机推荐
初识Opencv4.X----ROI截取
【cf】Round 128 C. Binary String
UI原型资源
How to obtain location information (longitude and latitude) by uni app
OC--包装类和处理对象
关于C和OC
Data control language (DCL)
OC--Foundation--字符串+日期和时间
Dream set sail (the first blog)
Swift简单实现待办事项
App的生命周期和AppleDelegate,SceneDelegate
@3-2 optimal threshold of CCF 2020-12-2 final forecast
uni-app小程序如何自定义标题内容(如何解决小程序标题不居中)
【代码源】每日一题 - 排队
[code source] daily one question three paragraph
【数据挖掘】最近邻和贝叶斯分类器
基于人脸识别的树莓派门禁系统
Flutter Rive 多状态例子
Laravel calls a third party to send mail (PHP)
【代码源】每日一题 树