Batch add or delete users

Source: Internet
Author: User

========================================================== ========================================================== ============

#! /Bin/bash

#

If [! $ #-EQ 1]; then

Echo './user. Sh -- add | -- del'

Exit 1

Fi


Case "$1" in

-- Add)

For I in {1 .. 10}

Do

If Id user $ I &>/dev/NULL; then

Echo "User $ I is exists ."

Else

Useradd user $ I

Echo "User $ I" | passwd -- stdin user $ I &>/dev/null

Echo "Add User user $ I finished ."

Fi

Done

;;

-- Del)

For I in {1 .. 10}

Do

If Id user $ I &>/dev/NULL; then

Echo "delete user $ I finished ."

Userdel-r user $ I

Else

Echo "User $ I is not found ."

Fi

Done

;;

*)

Echo './user. Sh -- add | -- del'

Esac

========================================================== ========================================================== ============


#! /Bin/bash


If [$ #-lt 2]; then

Echo "usage $0 -- add user1, user2, user3 | -- del user1, user2, user3 | -- help"

Exit 1

Fi

If [$1 = "-- add"]; then

For I in 'echo $2 | SED's/, // g''

Do

If Id $ I &>/dev/NULL; then

Echo "$ I exists ."

Exit 9

Else

Useradd $ I

Echo $ I | passwd -- stdin $ I &>/dev/null

Echo "Add User $ I finished ."

Fi

Done

Elif [$1 = "-- del"]; then

For I in 'echo $2 | SED's/, // g''

Do

If Id $ I &>/dev/NULL; then

Userdel-r $ I

Echo "delete user $ I finished ."

Else

Echo "No Sush $ I ."

Exit 9

Fi

Done

Elif [$1 = "-- Help"]; then

Echo "usage $0 -- add user1, user2, user3 | -- del user1, user2, user3 | -- help"

Else

Echo "usage $0 -- add user1, user2, user3 | -- del user1, user2, user3 | -- help"

Fi


This article from the "quiet fan Yin" blog, please be sure to keep this source http://mastters.blog.51cto.com/6516495/1530756

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.