Simple statement to add and delete users

Source: Internet
Author: User

Simple statement to add and delete users
GuideI am Su Xiaobai, a Chinese cabbage who has just entered the linux World. I have been learning about linux Through "linux should be like this" recently. I saw a question on the Internet a few days ago about how to add or delete shell script commands for common users. I didn't write it myself at the time, but I recorded the question! Later, I learned "linux should be like this" and completed what I needed. Hope you can see it. If there is anything incorrect, hope you can correct your message!Requirement: Edit shell script commands to add and delete common users.
Requirements:
1. To add or delete a common user, you must query whether the common user already exists.
2. Add (delete) to implement Circular inquiryThe Code is as follows:

#! /Bin/bashread-p "do you want to add a user? Yes (0) NO (1) "USERADD

Select Operation Type -- add or delete a user

Add User code
If [$ USERADD-eq 0] thenC = 1 while [$ C-eq 1] doread-p ", enter the account name: "UNAME # Add username # id $ UNAME &>/dev/null # check whether a user exists # if [$? -Eq 0] thenecho "account already exists! "Else read-p" Enter the account password: "PASSWD # Add password # useradd $ UNAME &>/dev/null # create user # echo" $ PASSWD "| passwd -- stdin $ UNAME &>/dev/null # create user password #

Do not add spaces in "$ PASSWD"; otherwise, the password will contain spaces!

If [$? -Eq 0] then echo "$ UNAME created successfully! "Elseecho" $ UNAME creation failed! "Fifiread-p" do you want to continue adding? Yes (1) No (0) "C # Set the variable" C "to implement Delete Code Execution in a loop # done
Delete user code

ElseDEL = 1 while [$ DEL-eq 1] doread-p "Enter the username to delete: "UNAME # username to be deleted # id $ UNAME &>/dev/nullif [$? -Eq 0] # delete a user query # thenuserdel-r $ UNAME # delete a user # echo "$ UNAME deleted successfully! "Elseecho" User $ UNAME not found! "Firead-p" do you want to continue? Yes (1) No (0) "DEL # Set the variable" DEL "to implement Delete Code Execution in a loop # donefi

Address: http://www.linuxprobe.com/user-add-del.html


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.