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

自动添加和删除用户

时间:2015-05-17 02:16:37      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:用户名   密码   null   


#!/bin/bash

#

#添加10个用户user1到user10,密码同用户名:但要求只有在用户不存在的情况下才能添加;

#删除10个用户user1到user10

if [ $# -lt 1 ];then

  echo "Usage:`basename $0` ARG"

  exit 7

fi

if [ $1 == add ];then

  for I in {1..10};do

     if id user$I &> /dev/null

        then

      echo "the user$I exist."

      else

      useradd user$I && echo "user$I" | passwd --stdin user$I &> /dev/null  

      echo "add user$I success."

   fi

 done


elif [ $1 == del ];then

  for I in {1..10};do

     if id user$I &> /dev/null

        then

          userdel -r user$I 

          echo "delete user$I ."

      else 

         echo "the user$I not exist."

      fi

   done


else

  echo such as user

fi


自动添加和删除用户

标签:用户名   密码   null   

原文地址:http://bunny.blog.51cto.com/920242/1651926

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