Bulk Add user's shell script

Source: Internet
Author: User

Title Requirements: Through Shell programming, to achieve bulk add users.

Save As any file name: Give x permission

Add user1.user2.user3....user10, Password = user name without any arguments

Plus parameter example: COMMAND-A Test 20 command-A add test is the user's first 20 is to add quantity (add up to no more than 100, the following code can be modified)

command-d test Deletes the user name in the system that begins with test, followed by a number, and without test, the USER1.USER2.USER3 is deleted by default ... This type of user ... Be careful with ...

#!/bin/bash U=${2:-user} num=${3:-10} res= ' Grep-o ' ^\< $U [0-9]\{1,\}\> '/etc/passwd|grep-o ' [0-9]\{1,\} ' |sort-n |tail-1 ' res1=${res:-0} res2=$ ((res1+num)) all= ' cat/etc/passwd|wc-l ' if [[Z $ | | | ' && = = $ &
                        & $3-le]];then for ((i=${res1};i<=${res2};i++)) do if [[$i-ne 0]];then Useradd ${u} $i &>/dev/null echo "${u} $i" |passwd--stdin ${u} $i && Gt /dev/null fi done aall= ' cat/etc/passwd|wc-l ' echo ' ADD user num
                BER is $ ((aall-all)) "Elif [[!-Z $ && '] = ' d ']]; then for ((i=${res1};i>=1;i--) do res3= ' grep-o ' ^\<${u}${i}\> '/etc/passwd ' if [[-N $Res 3 && ' ${u} $i ' = ' $
                Res3 "]];then userdel-r ${u} $i &>/dev/null fi done Dall= ' Cat/etc/passWd|wc-l ' echo ' Del user number is $ ((all-dall)) "Else Echo-e" \033[33;5merror!\033[0m please INP UT none or-a or-d "fi
Related Article

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.