一、编写脚本文件addUser.sh
#!/bin/bash
read -p "enter the users password: " Passwd
for uname in `cat users.txt`
do
id $uname &> /dev/null
if [ $? -eq 0 ]
then
echo "already exists"
else
useradd $uname &> /dev/null
echo "$Passwd" | passwd --stdin $uname &> /dev/null
if [ $? -eq 0 ]
then
echo "$uname, created success"
else
echo "$uname, created failure"
fi
fi
Done
二、编写用户名名单users.txt(注意:在windows下编写时会有问题)
User1
User2
User3
三、运行脚本:找到文件根目录 # ./addUser.sh
=========================================分割线==================================================
删除用户
# userdel 用户名(单纯删除用户不删除文件)
# userdel -r 用户名(删除用户及文件)