【shell脚本练习】批量添加用户和设置密码
2015-08-22 20:29
996 查看
题目
添加9个用户,user101…user109;密码同用户名;思路
for循环来添加就好了,用户名和密码都可以拼字符串来完成user10+数字
要判断是否能添加成功,注意非交互模式下修改用户密码的技巧
脚本
#!/bin/bash #addusers.sh echo "-----add 9 users-----" for i in {1..9}; do username=user10$i if useradd $username &> /dev/null; then echo "$username"|passwd --stdin $username #脚本中通常这样比较容易修改用户密码 if [ $? -eq 0 ]; then echo "add $username successful" else echo "$username added, change password failure " fi else echo "add $username failure " fi done
相关文章推荐
- 关于shell变量的第二个shell脚本
- bash的配置文件以及加载的顺序
- bash变量-用户自定义变量和环境变量/
- shell 常见的系统环境变量解析
- mac基础终端命令入门
- PowerShell命令卸载Win10内置应用
- Shell 的变量功能
- Bash脚本编程
- linux下的shell操作mysql
- Linux Shell 小脚本经典收藏
- Note For Linux By Jes(5)-认识与学习 BASH
- Python 问题--encode、decode及shell中文输出
- 零零碎碎写的shell脚本(三):一键自动归档压缩脚本
- shell 编程(难题分析)
- shell-init: error retrieving current directory: getcwd: cannot access parent directories
- 关于shell变量的第一个shell脚本
- 使用Xshell生成key,避免password登录linux
- Shell编程之Shell变量学习总结
- 我的第一个shell脚本
- 扯淡之浅谈bugbash