我的需求:
因网络限制,某些客户机ssh到服务器都得使用跳板机进行转一下,每次帮开帐户,不麻烦不难,但总觉得还可以再优。
不多说,直接放shell。很简单
#!/bin/bash
#test add user and set passwd
username=$1
adduser_log=/data1/useradd.log
password=`echo $username |md5sum|cut -c1-8`
if [ -n "$username" ]
then
#检查用户是否存在
if id -u $username >/dev/null 2>&1; then
echo "user exists"
else
echo "user does not exist,start set up"
useradd $username
echo $password | sudo passwd $username --stdin &>/dev/null
echo "增加成功:"$username/$password
echo "-----------增加成功:"$username/$password>>$adduser_log
fi
else
echo "script properties is cannot null"
fi