Linux command: Automatically add user

Source: Internet
Author: User
Tags stdin

1. Automatically add 10 User:

#adminuser. Sh

#!/bin/bash

#

if [= = '--add ']; Then

Fori in {1..10}; Do

If ID user$i &>/dev/null; Then

echo "user$i exists."

Else

Useradd user$i

echo user$i | passwd--stdin &>/dev/null

echo "Add user$i finished."

Fi

Done

elif [= = '--del ']; Then

Fori in {1..10}; Do

If ID user$i &>/dev/null; Then

Userdel-r user$i

echo "Delete User$i finished."

Else

echo "No user$i."

Fi

Done

Else

echo "is a Unknown ARG"

Exit8

Fi


2. Auto-Add User: adminuser2.sh--add USER1,... | --del User1,user2,... | --help

# VI adminuser2.sh

#!/bin/bash

If [$#-lt 1]; Then

echo "Usage:adminuser2.sh--add USER1,... |--del user1,user2 |--help"

Exit7

Fi


if [= = '--add ']; Then

Fori in ' Echo | sed ' s/,//g '; Do

Ifid $I &>/dev/null; Then

echo "$I exists."

Else

Useradd $I

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

echo "Add $I finished."

Fi

Done

elif [ = =--del]; Then

Fori in ' Echo | Sed ' s/,//g '; Do

Ifid $I &>/dev/null; Then

Userdel-r $I

echo "Delete $I finished."

Else

echo "$I not exist."

Fi

Done

elif [= =--help]; Then

echo "Usage:adminuser2.sh--add USER1,... | --del User1,user2 | --help "

Else

echo "unkown options."

Fi

---end---


Linux command: Automatically add user

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.