Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Shell script should use "seven" to create users in batch

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Create 10 system accounts name01-name10 in batch and set the password (password is a random 8-bit string

Script

#! / bin/bash

. / etc/init.d/functions

[$UID-ne 0] & & {

Echo "only allow root to exec this cmd."

Exit 1

}

For n in seq-w 10

Do

Pass= "$(echo $RANDOM | md5sum | cut-c 2-9)"

Useradd name$n & > / dev/null & &\

Echo $pass | passwd-- stdin name$n & > / dev/null

If [$?-eq 0]; then

Action "useradd name$n" / bin/true

Else

Action "useradd name$n" / bin/false

Fi

Echo-e "name$n\ t$pass" > > user.txt

Done

Note: the method of adding 0 before the number: seq-w 00 10 X echo {01.. 10}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report