把需要创建的用户名放在一个文件里,然后自动创建这些用户
效果图
代码如下:
-
#!/bin/bash
-
read -p "please enter the user's password: " passwd
-
for user in `cat /xie/q.txt`
-
do
-
id $user &> /dev/null
-
if [ $? -eq 0 ]
-
then
-
echo "user $user is exists"
-
else
-
useradd $user
-
echo "$passwd" | passwd --stdin $user &> /dev/null
-
if [ $? -eq 0 ]
-
then
-
echo "user $user create successfully"
-
else
-
echo "user $user create failed"
-
fi
-
fi
-
done
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31098809/viewspace-2126162/
,如需转载,请注明出处,否则将追究法律责任。