批量创建10个系统帐号o01-zkg10并设置密码(密码为随机8位字符串)
脚本如下:
#!/bin/sh
#批量创建用户名和密码
#by zkg 2019-08-22
. /etc/init.d/functions
if [ $UID -ne 0 ];then
echo "create user need root privage"
exit
fi
for user in echo zkg{01..10}
do
check_user=grep "\b$user\b" /etc/passwd|wc -l
if [ $check_user -ne 0 ];then
action "this $user is exist,no create user" /bin/false
continue
fi
PASSWD=`echo $RANDOM|md5sum|cut -c 1-8`
useradd $user && echo "$PASSWD"|passwd --stdin $user
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "$user is created successfully" /bin/true
else
action "PASSWD is failed" /bin/false
fi
echo "$user:$PASSWD" >>/opt/shell/passwd.txt
done
原文地址:https://blog.51cto.com/1009516/2431803
时间: 2024-11-06 05:43:49