批量增加用户

类别:软件工程 点击:0 评论:0 推荐:
http://bbs.chinaunix.net/forum/viewtopic.php?t=405818&highlight=批量
newcmd  

看了“零二年的夏天“写的批量增加用户的脚本,有几个地方不明白#!/bin/sh
#Name:smbadd
#Des:To add some samba user
#Author:PopZslam

_PASSWD=123456
_SMBNAME=
_SMBGROUP=samba #Sorry, I forget the samba group's name.You can edit this script and input the currect name.

MyAdd ()
{
adduser $_SMBNAME -g $_SMBGROUP
echo "The smbuser" $_SMBNAME "is added to "$_SMBGROUP!
echo "Set password for smbuser"
echo $_PASSWD|passwd $_SMBNAME --stdin
}

USERLIST ()
{
if [ -f ~/smbuserlist ] ; then

i=1
while
_NUM=`head -n $i ~/smbuserlist|awk '$1==i {printf "%s",$1;next;}' i="$i"`
do
if [ -z $_NUM ] ; then
echo "There is no user to add!!"
exit 0
else
_SMBNAME=`awk '$1==i {printf "%s",$2;next;}' i="$i" ~/smbuserlist`
MyAdd
i=`expr $i + 1`
fi
done
else
echo "You Must create a file named \"smbuserlist\" first!"
fi
}

#main part
USERLIST
#End

红色的地方不是太明白,不过我依据自己的理解做了一些修改,做成了可以添加有不同密码的用户。不明白的地方还希望高手给解释一下。
下面是我的脚本,欢迎指正。
#!/bin/sh

_PASSWD=
_SMBNAME=
_SMBGROUP=samba #Sorry, I forget the samba group's name.You can edit this script and input the currect name.
_SHELL=/bin/noshell

MyAdd ()
{
adduser $_SMBNAME -g $_SMBGROUP -s $_SHELL
echo "The smbuser" $_SMBNAME "is added to "$_SMBGROUP!
echo "Set password for smbuser"
echo $_PASSWD|passwd $_SMBNAME --stdin
}

USERLIST ()
{
if [ -f ~/smbuserlist ]
then
i=1
while
_SMBNAME=`awk -F , "NR==$i {print \\$1}" ~/smbuserlist`
_PASSWD=`awk -F , "NR==$i {print \\$2}" ~/smbuserlist`
do
if [ -z $_SMBNAME ]
then
echo "there is no user to add"
exit 0
else
MyAdd
i=`expr $i + 1`
fi
done
else
echo "you must add the smbuserlist file"
fi
}

#main part
USERLIST
#End

注:RedHat9.0测试通过。
smbuserlist文件的格式为user,password每行一个用户

本文地址:http://com.8s8s.com/it/it34133.htm