Shell编程-批量增删用户

此为以前写的代码,整理中,未完待续

Shell整理

批量增加用户

批量增加用户文件 batAddUser.sh
运行

./batAddUser.sh 
#!/bin/bash
# add User more times
read -p "Please input user name:" -t 30 name
read -p "Please input the number of users:" -t 30 num
read -p "Please input the password of users:" -t 30 pass
 # ! -z "$name" -a ! -z "$num" -a ! -z "$pass"
if [ ! -z "$name" ]
  then
  if [ ! -z "$num" ]
    then
    if [ ! -z "$pass" ]
    then
    y=$( echo $num | sed 's/[0-9]//g' )
        if [ -z "$y" ]
        then
        for (( i=1; i<=$num; i=i+1 ))
            do
                useradd $name$i &> /dev/null
        # userdel $name$i &> /dev/null
                echo $pass | pass --stdin $name$i &> /dev/null
            done
        fi
     else
        echo "password is not mull "
     fi
  else 
    echo "number is not null"
  fi 
else
   echo "user is not null"  
fi

代码说明:

批量删除普通用户

批量增加用户文件 delRUser.sh
运行

./delRUser.sh       
#!/bin/bash
# delete regular user expect for root

for i in $(cat /etc/passwd | grep /bin/bash | grep -v root | cut -d ":" -f1)
    do
          userdel -r $i
    done

代码说明:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值