在linux系统中,多台服务器,每个都需要创建用户和用户组,从而写个脚本来自动创建注意:1、必须用root用户来执行2、必须用户名和用户id在系统中未被使用,如果被使用,请修改脚本中相关设置3、例子中的用户名分别为weblogic和log,用户组为bea4、log用户专门用来存放日志,weblogic为运行程序用户,同属组bea5、例子中的weblogic的id为500,log的id为501,组bea的id为500

公众号:SRE艺术

#!/bin/bash
#Program:
# This program is used to create user
#History:
#20120706 kel First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin
export PATH




#must use root to start the sh
if [ -z "`id |grep "root" `" ] ; then
echo "must use root to start the sh,please contact the administrator"
exit 0;
else
#check the username and the group name was exist
if [ ! -z "`cat /etc/passwd |grep "^weblogic" `" ] || [ ! -z "`cat /etc/group |grep "^bea"`" ] || [ ! -z "`cat /etc/passwd |grep "^log"`" ] || [ ! -z "`cat /etc/passwd |cut -d ":" -f3|grep "50[01]"`" ] || [ ! -z "`cat /etc/group |cut -d ":" -f3 |grep "500"`" ] ; then
echo "username or groupname or userid or groupid  was exist,please checkin"
exit 0;
fi
fi
#add the user and the group
groupadd -g 500 bea
useradd -u 500 -g 500 -d /home/weblogic weblogic
useradd -u 501 -g 500 -d /home/log log


#change the password and the password was same as the username
echo "PLEASE INPUT THE weblogic AND log  PASSWORD"
passwd weblogic


passwd log


#checkin the password was change"
if [ -z `cat /etc/shadow |grep "^weblogic" |grep "\!"` ];then
echo "weblogic password was change successful"
else
echo "weblogic password was not change"
fi


if [ -z `cat /etc/shadow |grep "^log" |grep "\!"` ];then
echo "log  password was change successful"
else
echo "log  password was not change"
fi


chmod 770 /home/log
echo "ADD SUCCESS. add user log and weblogic,uid was 500 and 501 ,add group bea and the gid is 500"


#delete the group and the users
#if [ ! -z $1 ];then
# echo "delete the group and the users"
# userdel -rf log
# userdel -rf weblogic
# groupdel bea
# else
# echo "not delete the group and the users "
#fi

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐