用户名自定义:
#!/bin/bash
read -ep "要创建的用户数量" num
for ((i=0;i<=$num;i++))
do
read -ep "请输入要创建的用户名" username
passwd=`date +%s%N | md5sum | head -c 6`
cat /etc/passwd|grep -w $username >/dev/null
if [ $? -eq 0 ]
then
echo "$username用户已存在"
echo -e "1.删除用户\n2.跳过"
read -ep "请选择你的操作" num
case $num in
1)
userdel -r $username
;;
2)
continue
;;
esac
else
useradd $username
echo "$username:$passwd"|chpasswd
echo "$username,$passwd" >> /root/shell/user.txt ##将用户信息重定向到/root/shell/user.txt中。
fi
done
用户名用默认的
#!/bin/bash
read -ep "要创建的用户数量" num
for ((i=0;i<=$num;i++))
do
passwd=`date +%s%N | md5sum | head -c 6`
cat /etc/passwd|grep -w user_$i >/dev/null
if [ $? -eq 0 ]
then
echo "user_$i用户已存在"
echo -e "1.删除用户\n2.跳过"
read -ep "请选择你的操作" num
case $num in
1)
userdel -r $username
;;
2)
continue
;;
esac
else
useradd user_$i
echo "user_$i:$passwd"|chpasswd
echo "user_$i,$passwd" >> /root/shell/user.txt
fi
done