具体脚本如下:

#!/bin/bash


USER_NAME=$1

USER_FOLDER=$2

USER_PASSWORD=$3

#echo "1-$USER_NAME,2-$USER_FOLDER,3-$USER_PASSWORD"

name=`/bin/cat /etc/passwd | /bin/awk -F ':' '{print $(1)}' | /bin/grep -E "^$USER_NAME$"`
echo "检查到的用户名为:$name"

if [ ! $name ]; then
 echo "当前系统中没有用户$USER_NAME"
 echo "-----------------------------------------------------------------------------------------------------------"
 echo "创建用户组$USER_NAME"
 groupadd $USER_NAME
 echo "创建用户$USER_NAME"
 adduser $USER_NAME -g ftp
 echo "给用户设置密码"
 echo $USER_PASSWORD | passwd $USER_NAME --stdin >/dev/null 2>&1;
 # 这里可以自定义添加用户组
 # gpasswd -a $USER_NAME ftp
 echo "创建用户目录"
 mkdir -p $USER_FOLDER;
 echo "给用户目录授权"
 /bin/chmod 777 -R $USER_FOLDER;
 echo "---------------------------------------------用户$USER_NAME创建完毕------------------------------------------"
else
 echo "当前系统中用户$USER_NAME已存在!"
fi

使用方法:

sh create_user.sh user2 user2 user1234567890