Create 10 users in bulk, and set a random 8-bit password that requires no shell loops (for example: For,while, etc.) and can only be implemented with Linux commands and pipelines.
method 1:
[[email protected]/]# echo stu{01..10}|tr "" \ n "|sed-r ' s# (. *) #useradd \1; pass=$ ((random+10000000)); echo "$pass" |passwd--stdin \1; Echo-e "\1 \ t ' echo" $pass "'" >>/tmp/oldboy.log#g ' |bash
The above command is actually a re-spell . N The following combination of commands, take a command stu01 The user's procedure is disassembled as follows:
Useradd stu01;
pass=$ ((random+10000000));
echo "$pass" |passwd--stdin stu01;
Echo-e "Stu01 ' echo" $pass "'" >>/tmp/oldboy.log
method 2: Come from a drunken meal
echo stu{1..10}|xargs-n1 useradd; Echo stu{11..12}: ' Cat/dev/urandom|tr-dc 0-9|fold-w8|head-1 ' |xargs-n1|tee-a pass.t xt|chpasswd
method 3: Gorgeous from D -Tone
Echo stu{21..30} | Tr ' \ n ' | Sed-e ' S/^/useradd/'-E ' s/\ (stu[0-9]\{2\}\) $/\1 \&\& echo "\ 1: ' Echo $[$RANDOM **3] | Cut-c1-8 ' "| Tee-a UserInfo.txt | Cut-d:-f2 | passwd--stdin \1/' | Bash
function : 10 users are stu21-stu30 random userinfo.txt Span style= "font-family: ' The song Body '; >, format username:passwd above the random number I used to build the date, is not right, because there may be a repetition, so I then simply use random**3 8 bit, which ensures uniqueness.
method 4: from freeandeasy
Echo stu{01..10} |tr ' \ n ' |sed-rn ' [email protected]^ (. *) [email protected] \1; echo $RANDOM |md5sum|cut-c 1-8 >/data/\1;cat/data/\1|passwd--stdin \[email protected] ' |bash
method 5:
Echo ' Cat/dev/urandom | head-1 | md5sum | Head-c 8 ' | passwd--stdin stu{01..10}
method 6: from Li Yu LC
echo stu{01..10}|tr "" \ n "|sed-r ' s# (. *) #useradd \1;lc=$ ((RANDOM+10000000)); echo "$LC" |passwd--stdin \1#g ' |bash
method 7: from luolin--4200
echo stu{01..10}:$ (date +%N) |sed ' s# #\n#g ' >/mnt/pass;awk-f ': ' {print $} '/mnt/pass |xargs-n 1 US ERADD;PWUNCONV;CHPASSWD </mnt/pass;pwconv
method 8: From the guilty two of the three
echo A2stu{01..10}|xargs-n1|awk ' {print ' Useradd "$" && mkpasswd-l 8 >>/tmp/mima.txt;tail-1/tmp/mima.tx T|PASSWD--stdin "$} ' |bash
Each road great God, passing has better method, still hope not Sik Sik Yuen Enlighten!
Linux real-Life quiz: Create users and Passwords in batches (you can't use loops)