批量添加删除用户
Posted 岁月童话
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量添加删除用户相关的知识,希望对你有一定的参考价值。
批量添加用户
#!/bin/bash read -p "Enter the User Password : " PASSWD for UNAME in `cat users.txt` do id $UNAME &> /dev/null if [ $? -eq 0 ];then echo "Already exists" else useradd $UNAME &> /dev/null echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null if [ $? -eq 0 ];then echo "Create "$UNAME" success" else echo "Create failure" fi fi done
批量删除用户
#!/bin/bash for UNAME in `cat users.txt` do grep $UNAME /etc/passwd &> /dev/null if [ $? -eq 0 ] then userdel -r $UNAME echo "$UNAME is deleted!" else echo "$UNAME is not exist" fi done
以上是关于批量添加删除用户的主要内容,如果未能解决你的问题,请参考以下文章