博客
关于我
企业级-Shell案例3——批量创建多个用户并设置密码
阅读量:350 次
发布时间:2019-03-04

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

批量创建用户并设置密码

背景:多名新人入职

 

单个用户创建

添加

useradd zhang

改密码

passwd zhang

脚本编写

#!/bin/bash  USER_LIST=$@  USER_FILE=./user.info  for USER in $USER_LIST;do  	if ! id $USER >/dev/null; then  		PASS=$(echo $RANDOM |md5sum |cut -c 1-8)  		useradd $USER  		echo $PASS | passwd --stdin $USER >/dev/null  		echo "$USER   $PASS" >> $USER_FILE  		echo "$USER User create successful."  	else  		echo "$USER User already exists!"  	fi  done

使用示例:

./user.sh li zhang wei wu yi

相关博文:

转载地址:http://zfdr.baihongyu.com/

你可能感兴趣的文章
Python SOCKS5代理客户端HTTPS
查看>>
Python Soc网络分析:通过使用函数迭代列表来计算机会网络
查看>>
Python Sphinx自动摘要:成员函数的自动列表
查看>>
Python SQL和NoSQL数据库操作实战
查看>>
python stdout flush_sys.stdout.flush()方法的用法
查看>>
python string 运算
查看>>
Python str与bytes之间的转换
查看>>
Python subprocess ffmpeg
查看>>
python subprocess Permission denied Errno 13
查看>>
Python subprocess.call - 将变量添加到 subprocess.call
查看>>
Python Subprocess.Popen 从一个线程
查看>>
Python subprocess.Popen 作为 Windows 上的不同用户
查看>>
Python subprocess.Popen() 等待完成
查看>>
Python sum 二维列表中具有相同第一个值的元素
查看>>
Python Sympy模块NoConversion:收敛到根失败;请尝试n<;15或MaxSteps>;50
查看>>
python time模块
查看>>
Python Tkinter Multiple Windows 教程
查看>>
Python tkinter 中的多处理
查看>>
python try except finally_Python3基础 try-except-finally 的简单示例
查看>>
Python tweepy写入到sqlite3 db
查看>>