In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Two practical examples of Shell script analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Today, we mainly share two examples of shell scripts, the content is not important, the focus is to see how to implement.
1. Create users with special requirements in batch
Requirements: batch create 10 system accounts hwb01-hwb10 and set password (password is random number, requires mixed characters and numbers, etc.).
Script:
#! / bin/bash # File Name: add_user.sh # # Passwd_File=/tmp/ `uidgen`.txt > $Passwd_File chmod 400 $Passwd_File for i in hwb {01.10} do userdel-r "$I" & > / dev/null id $I & > / dev/null if [$?-ne 0] then useradd $I PassWd= `uuidgen` echo $PassWd | passwd-- stdin $I & > / dev/null echo "user name: $I password: $PassWd" > $Passwd_File echo-e "\ 033 [32m $I user created successfully! \ 033 [0m "else echo" $I user already has "fi if [" $I "=" hwb10 "] then echo" user password Please check the file $Passwd_File "fi done
Results:
Ps: batch create users and set random passwords (without using shell loops)
Method 1:
Echo user {1... 20} | xargs-N1 | sed-r's # (. *) # useradd\ 1\ &\ & echo\ 1 > > / tmp/passwd.txt\ &\ & echo $RANDOM | md5sum | cut-c 1-5 > > / tmp/passwd.txt\ & & echo `tail-1 / tmp/ passwd.txt` | passwd-stdin\ 1passg` | bash
Method 2:
Echo user {1... 20} | xargs-N1 | sed-r's # (. *) # useradd\ 1\ & pass= `echo $RANDOM | md5sum | cut-c 1-5`\ & echo $pass | passwd-stdin\ 1\ & echo\ 1$ pass > > / tmp/user_passwd.txt#g' | bash
Method 3:
Echo user {1... 20} | xargs-N1 | sed-r's # (. *) # useradd\ 1\ & pass= `echo $RANDOM | md5sum | cut-c 1-5`\ & echo\ 1:$pass > > / tmp/user_passwd.txt\ &\ & chpasswd
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
View service name delete service open cmd input command sc delete TlntSvr
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.