1、增加用户的时候,用户名和组名不能存在,否则不能运行

2、运行用户必须为root

3、增加用户和组的时候,用户id和组id不能被占用,否则不能运行

4、用户的密码已经修改

5、如果运行的时候添加了参数,那么就是删除这些用户


#!/bin/bash

#Program:
#       This program is used to create user
#History:
#20120706       kel     First release
#20120708       kel     add not to input the password
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin
export PATH




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


#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"
echo "weblogic"|passwd --stdin weblogic > /dev/null 2>&1


echo "log" |passwd --stdin log > /dev/null 2>&1

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


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


chmod 770 /home/log
echo "ADD SUCCESS."



Logo

更多推荐