Linux 学习笔记:批量新增SAMBA用户的脚本
#!/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
轉載于:https://blog.51cto.com/coosh/1732519
總結
以上是生活随笔為你收集整理的Linux 学习笔记:批量新增SAMBA用户的脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unable to execute de
- 下一篇: 关于Java去连接HTTP地址的操作