1、建账号脚本usercreate.sh,设为可执行 #chmod +x usercreate.sh

内容如下:

#! /bin/bash
for username in $(cat list)
do
         id $username > /dev/null 2>&1      #判断账号是否已经存在
   if [ $? = 0 ]               
   then
    echo "The user: $username is exist"    
   else         
   useradd $username
                cp /u1/usr/topgui/.profile /u1/usr/$username
                echo $username | passwd --stdin "$username"    #通过标准输入stdin自动初始化密码为和用户名相同                 
                echo "user $username have been created!"                     
                echo "$username 's password is $username."                      
                echo "-----------------------------------------"
   fi
done

2、在脚本所在目录新建文件list,把要建立的账号放入,格式是一行一个,如:

000001
000002
000003

3、 #./usercreate.sh