码迷,mamicode.com
首页 > 其他好文 > 详细

批量添加删除用户

时间:2016-09-26 13:07:06      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

 

 批量添加用户

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

 

批量添加删除用户

标签:

原文地址:http://www.cnblogs.com/love3556/p/5908560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!