#! /bin/sh
#添加一个新组,然后添加属于这个组的10个用户,用户名的形式为stdxx,其中xx从01到10
#添加一个新组
user_pr=std
time=$(date)
read -p "Please input a newgroupname: " groupname
groupadd $groupname
echo " $time have add or change group '$groupname' to /root/newuser.txt ">>/root/newuser.txt
while [ -z "$groupname" ]
do
echo "groupname error!please input groupname!\n"
read -p "Please input a newgroupname: " groupname
groupadd $groupname
echo " $time have add or change group '$groupname' to /root/newuser.txt ">>/root/newuser.txt
done
echo
for n in 01 02 03 04 05 06 07 08 09 10
do
useradd -g $groupname $user_pr$n
echo "Please input password for '$user_pr$n'\n "
passwd $user_pr$n
echo " $time have add or change user '$user_pr$n' to /root/newuser.txt ">>/root/newuser.txt
echo
done
#cat /etc/passwd | grep
echo ++++++++++++++++++++++++++++++++++
####################参考脚本####################
#for i in 9901 9902 9903 9904
#do
# xx=$(echo $i | sed 's/99//g')
# useradd -g $groupname std$xx
# echo std$xx | passwd std$xx
# echo -e "user std$xx password is std$xx" >> /root/newuser.txt
#done
exit 0
阅读(483) | 评论(0) | 转发(0) |