批量添加删除用户

 

 批量添加用户

#!/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

 

posted @ 2016-09-26 11:38  岁月童话  阅读(909)  评论(0编辑  收藏  举报