[Linux] 批量添加用户

编写两个文件,一个文件user.list用于存放用户名,另一个sh文件用来作为批量添加用户的linux脚本。 

adduser.sh

#!/bin/bash
#用for循环读取users.list文件中的用户名数据,并保存在name变量中
#根据读入的用户名创建相应的用户帐号,并设置用户口令为<用户名>123
#实现批量添加用户帐号的目的


for name in 'more users.list'
do
#while name is not null
if [ -n "$name" ]
then
# add the users
useradd -m $name
echo
# set the passwd
echo $name"123" | passwd --stdin "$name"
echo
echo"user $username's password changed!"
#while name is null
else
echo
#echo the information that username is mull
echo 'the username is null!'
fi
done

posted @ 2012-11-16 16:30  Aviva_ye  阅读(226)  评论(0编辑  收藏  举报