add more users

#!/bin/bash

# addclass ga 1 50  username ga0101-ga0150

groupadd users 2>> /dev/null
if [ $? -eq 0 ]
then
echo "Users is created seccussfully !"
else
echo "Users is exist,you needn't created !"
fi
grade=$1
num_class=`expr $2 + 0`

if (test $num_class -le 9)
    then
num_class="0"$num_class
fi

max_stid=`expr $3 + 0`
num_stid=1

if [ ! -x /home/student ]
then
mkdir /home/student
fi

if [ ! -x /home/student/$1$num_class ]
then
mkdir /home/student/$1$num_class
fi

while (test $num_stid -le $max_stid)
do
if (test $num_stid -le 9)
then
num_stid="0"$num_stid
fi
user_name=$grade$num_class$num_stid
echo $user_name":"$user_name >> user_pwlist
adduser -g users -d /home/student/$1$num_class/$user_name $user_name
#setquota -u $user_name 10240 20480 0 0 /home
chmod 755 /home/student/$1$num_class/$user_name
num_stid=`expr $num_stid + 1`
done

chpasswd < user_pwlist
pwconv
/bin/rm -f  user_pwlist

你可能感兴趣的:(shell)