代码拉取完成,页面将自动刷新
#!/bin/bash
help() {
echo "usage: add_group.sh <user> [group]"
echo " if group is empty, group equals user"
exit 1
}
if [[ "-h" == "$1" ]] || [[ "--help" == "$1" ]]; then
help
fi
USER=$1
GROUP=$2
if [[ "" == "${USER}" ]]; then
help
fi
if [[ "" == "${GROUP}" ]]; then
GROUP=$USER
fi
echo "USER=${USER}"
echo "GROUP=${GROUP}"
# 添加新用户组
group_info=`grep -E "^${GROUP}:" /etc/group`
echo group_info=$group_info
if [[ "" == "$group_info" ]]; then
# 用户组不存在,则添加用户组
echo "add group ..."
groupadd $GROUP
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: add new group is failed. group=${GROUP}"
exit $ret
fi
echo "group add success"
else
echo "group \"${GROUP}\" exists"
fi
# 向组中添加新用户
id $USER
ret=$?
if [[ 0 -ne $ret ]]; then
# 用户不存在,则添加用户
echo "add user ..."
useradd $USER -m -s /bin/bash -g $GROUP
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: useradd is failed. user=${USER}"
exit $ret
fi
echo "user add success"
else
echo "user \"${USER}\" exists"
fi
echo "new user password:"
passwd $USER
ret=$?
if [[ 0 -ne $ret ]]; then
echo "$LINENO: passwd ${USER} is failed. user=${USER}"
echo $ret
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。