批量添加用户
#!/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
时间: 2024-10-12 00:17:37