Write a script to add and remove users by using the character menu method

Source: Internet
Author: User

1. Writing menu.sh Scripts

#!/bin/bash#function menu () {cat << EOF ' echo-e ' \033[30;47m########################################\033[0m ' ' Echo-e ' \033[32mmy menu\033[0m "' Echo-e" \033[30;47m########################################\033[0m "' * ' EC Ho-e "\033[35m1) Add a user\033[0m" ' * ' Echo-e "\033[35m2) Delete a user\033[0m" ' * ' Echo-e "\033[35m3) quit\033 [0m "' * ' Echo-e" \033[35m4) return main menu\033[0m "' EOF}


2. Write adminuser.sh script #!/bin/bash

#clear . menu.shmenuwhile true;doread -p  "please inoput a option: "  option    case  $option  in       1)         read -p  "add a user: "  name         read -p  "Set passwd for the user :  " pass        useradd  $name  &>/dev/null         if [ $? -eq 0 ];then           echo -e  "\033[32;40m$name is created  Succesufully!!! \033[0m "          echo  $pass  | passwd -- stdin  $name  &>/dev/null        else           echo -e  "\033[32;40muser  $name  is created failly!!! \033[0m "        fi        ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2)         read -p  "delete a user: "  name        userdel -r   $name  &>/dev/null        if [ $? -eq  0 ];then          echo -e  "\033[32;40m$ Name is deleted successfully!!! \033[0m "        else           echo -e  "\033[32;40m$name is deleted failly!!! \033[0m "        fi        ;;        3)        echo -e  "\033[32; 40mquit successfully!!! \033[0m "       break       ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;4)        clear        menu       ;;     esacdone


3. Test scripts

#./adminuser.sh

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/41/wKiom1XfE-WBpwXnAAGEG1QHoUk566.jpg "style=" float: Left; "title=" 27.PNG "alt=" Wkiom1xfe-wbpwxnaageg1qhouk566.jpg "/>


This article is from "Xiao Zeng" blog, please be sure to keep this source http://zengxin.blog.51cto.com/6098070/1689082

Write a script to add and remove users by using the character menu method

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.