软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
批量增加用户

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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每行一个用户




相关文章

相关软件