批量创建用户并设置随机密码
批量创建用户并设置随机密码:
#!/bin/bash
. /etc/init.d/functions
user=freddy
Path=/data/
UserDb=$Path/user.db
FailDb=$Path/user.db
[ -d "$Path" ] || mkdir $Path
[ -f "$UserDb" ] || touch $UserDb
[ -f "$FailDb" ] || touch $FailDb
for n in $(seq -w 10);do
passwd=`echo $(date +%t%N)$RANDOM|md5sum|cut -c 2-9`
useradd $user$n >&/dev/null&& user_status=$?
echo "$passwd"|passwd --stdin $user$n >&/dev/null && pass_status=$?
if [ $user_status -eq 0 -a $pass_status -eq 0 ];then
action "adduser $user$n"/bin/true
echo -e "user: $user$npass:$passwd" >>$UserDb
else
action "adduser $user$n"/bin/false
echo -e "user: $user$npass:$passwd" >>$FailDb
fi
done