#!/bin/bash
# version
# date
# author
. /etc/init.d/functions
user="Uname_"
passfile=/tmp/passfile.log #存储用户密码文件
if [ ! -f $passfile ];then
touch $passfile
fi
for i in `seq 31 40`
do
pass=`echo "test@$RANDOM"|md5sum|cut -c 3-13`
useradd $user$i &>/dev/null && echo "$pass" |passwd --stdin $user$i
echo -e "user:$user$i\tpasswd:$pass" >>$passfile
if [ $? -eq 0 ];then
action "$user$i is ok " /bin/true
else
action "$user$i is fail " /bin/false
fi
done
echo ----------------------------------------------------
cat $passfile
echo ****************************************************
#!/bin/bash
# version
# date
# author
. /etc/init.d/functions
file=/tmp/passfile.log
while read LINES
do
user=`echo $LINES|awk '{print $1}'|cut -d':' -f2`
passwd=`echo $LINES|awk '{print $2}'|cut -d':' -f2`
useradd $user
if [ $? -ne 0 ];then
echo "$user exists,skip set password"
action "$user is fail " /bin/false
else
echo $passwd|passwd --stdin $user
action "$user is ok" /bin/true
fi
done < $file
echo ***************************************************
#!/bin/bash
# description 批量删除用户
# author
. /etc/init.d/functions
file=/tmp/passfile.log
array=(`cat $file|awk '{print $1}'|awk -F":" '{print $2}'`)
for i in ${array[*]}
do
userdel -r $i
if [ $? -eq 0 ];then
action "$i is ok" /bin/true
else
action "$i is fail" /bin/false
fi
done