linux创建用户小脚本,添加部分修改

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."



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值