Shell脚本_创建系统用户,从一个用户列表文件(6.18重构)。
2016-06-19 16:26
696 查看
#!/bin/bash #This shell script is used to add user from a list of files. #So, it must have a file name as a parameter. #If you specify group name, this shell script to add all users to the group. #Usage: ThisSH filename [groupname] #Author: Mach #Modify time: 12.11/2015,create #Modify time: 06.18/2016,add: determine the user identity, refactoring function Adduser(){ for NM in $(cat $1) do useradd $NM && echo "Add user $NM successful." if [ ! -z $2 ]; then usermod -G $2 $NM && echo "Add user $NM to group $2 successful." fi echo -e "user:$NM\t\tgroup:$(id -Gn $NM)" >> ./newadduserlist.log echo $RANDOM | tee -a ./newadduserlist.log | passwd --stdin $NM echo -e "\n" >> ./newadduserlist.log done } if [ ! $UID = 0 ]; then echo "Error: Only root can add users." exit 1 elif [ $# = 0 ]; then echo "Error: No parameters." exit 2 elif [ ! -f $1 ]; then echo "Error: File $1 non-existent." exit 3 fi case $# in 1) Adduser $1 ;; 2) grep -w "^$2" /etc/group &> /dev/null if [ ! $? = 0 ]; then useradd -Ms /sbin/nologin $2 && echo "Add UNIgroup $2 successful." echo "$(id -un $2) (unified ID group)" >> ./newadduserlist.log echo -e "\n" >> ./newadduserlist.log fi Adduser $1 $2 ;; *) echo "Error: Parameters error." ;; esac
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- Shell 脚本编程陷阱
- VBS脚本写的Windows硬件检测工具分享
- 用vbscript实现隐藏任务栏图标的脚本
- 用autoit编写第一个脚本(Hello World)
- VBS调用WMI快速关闭IE的脚本
- Oracle数据库执行脚本常用命令小结
- 收集的ROS防火墙脚本
- JSP脚本漏洞面面观
- shell字符串操作详解
- 不错的批处理脚本 第一部分
- VBS脚本加密/解密VBS脚本(简易免杀版1.1)
- 不错的批处理脚本实例代码 第二部分
- 使用脚本和批处理清除电脑中的痕迹的代码第1/2页