Add multi-user or delete a multiuser small script

Source: Internet
Author: User
Tags egrep

Write a can add multi-user, delete multi-user small script, the user separated by a space can be, the following directly on the code:


#!/bin/bash

#discription: This file can add users or delete users.

#author: Zhai

#version: 0.1


Read-p "Want to add users or delete users,please choose (add|delete|quit):" Choose

Choose= ' echo $choose | Tr ' A-Z ' A-Z '

Case $Choose in

A|ADD|AD)

#add users

Read-p "Who does you want Useradd:" AddUser

For add in ' Echo ' $adduser | Egrep-o "[[: alnum:]]+" '

Do

If ID $add &>/dev/null;then

echo "User ' Echo-e" \033[31m "$add" \033[0m "' does exist ' && ID $add

Else

Useradd $add &>/dev/null && echo "Add user ' Echo-e" \033[31m "$add" \033[0m "'" && ID $add

Fi

Done

Exit

;;

D|delete|de|del|dele|delet)

#delete Users

Read-p "Who does you want Userdel:" User

For del in ' Echo ' $user | Egrep-o "[[: alnum:]]+" '

Do

If ID $del &>/dev/null;then

Userdel-r $del &>/dev/null && echo "Userdel ' Echo-e" \033[35m "$del" \033[0m "'"

Else

echo "No User: ' Echo-e" \033[33m "$user" \033[0m ""

Fi

Done

Exit

;;

Q|quit|qu|qui)

Exit

;;

*)

echo "Your Choose error!" && $ #此处用 $, script does not exit, new use script

;;

Esac


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/EF/wKioL1ev3W6RPSZ0AAD5Ony1TbY905.jpg "title=" Multi-user add and delete. jpg "alt=" wkiol1ev3w6rpsz0aad5ony1tby905.jpg "/> Script test diagram



This article is from the "zebra930" blog, make sure to keep this source http://zebra930.blog.51cto.com/11736340/1837738

Add multi-user or delete a multiuser small script

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.