#!/bin/bash
#先设定起始组名,根据实际需要设定。
group=op
#检查参数个数
if [ $# -ne 1 ]; then
echo "Usage: $0 <USERNAME>"
exit 1
else
username=$1
fi
#检查用户是否已经存在,如不存在则添加
#check the user exsit
pdbedit -L | grep "^$username:" &>/dev/null
if [ $? -ne 0 ]; then
useradd -M -s /sbin/nologin -g $group $username
echo ‘password‘ | passwd --stdin $username 1>/dev/null 2>>addsmbuser.log
echo -e "password\npassword" | pdbedit -a -t -u $username 2>>addsmbuser.log
if [ $? -eq 0 ]; then
echo "$username created!"
exit 0
else
echo "Oops,something wrong..."
exit 1
fi
else
echo -e "$username exsit in tdb,\nif you want to change its password, please use smbpasswd"
fi
#pdbedit不能用于修改密码,如要修改,仍旧使用smbpasswd
原文:http://coosh.blog.51cto.com/6334375/1732519