1)使用for迴圈在/westos目錄下批量建立10個html檔案,其中每個檔案需要包含10個隨機小寫字母加固定字串westos
#!/bin/bash
path=/westos
[ -d "$path"]||
mkdir -p $path
for i in
`seq 10`
do random=
$(openssl rand -base64 40 |
sed's/[^a-z]//g'
|cut -c 3-12)
touch
$path/$_westos.html
done
2) 建立10個使用者westos(01-10),並設定其密碼為10位隨機數
[root@server tmp]
# cat random.sh
#!/bin/bash
. /etc/init.d/functions
user=
"westos"
passfile=
"/tmp/user.log"
for num in
`seq -w 10`
do pass=
"`echo $random | md5sum |
cut -c 3-12`
"useradd
$user
$num
&> /dev/null &&if[
$? -eq 0 ]
;then
action "$user
$num is ok" /bin/true
else
action "$user
$num is failed" /bin/false
fidone
[root@server tmp]
# sh random.sh
westos01 is ok [ ok ]
westos02 is ok [ ok ]
westos03 is ok [ ok ]
westos04 is ok [ ok ]
westos05 is ok [ ok ]
westos06 is ok [ ok ]
westos07 is ok [ ok ]
westos08 is ok [ ok ]
westos09 is ok [ ok ]
westos10 is ok [ ok ]
[root@server tmp]
# cat /tmp/user.log
user:westos01 passwd:7fdb143dd9
user:westos02 passwd:6476ef99ad
user:westos03 passwd:3962f843f4
user:westos04 passwd:feb2f5d496
user:westos05 passwd:7890eeabcf
user:westos06 passwd:fa10a849f4
user:westos07 passwd:a740ee29f3
user:westos08 passwd:87e0eb374c
user:westos09 passwd:293d9243f0
user:westos10 passwd:878c4df9f4
shell 生成隨機數
用shell生成隨機數的方法有很多,但生成數字隨機數比較方便的方法還是以下幾種 1.使用shell的內建變數 random 生成0 32767之間的整數隨機數 echo random echo random 50 1 隨機生成從1 50之間是數 2.借助時間戳 date s 或 date s n 生...
shell指令碼隨機數練習
使用for迴圈在 westos目錄下批量建立10個html檔案,其中每個檔案需要包含10個隨機小寫字母加固定字串westos bin bash path westos d path mkdir p path for n in seq 10 do random openssl rand base64 ...
使用shell生成隨機數
1 bin bash 2for i in seq 1 1 3 do4for j in seq 1 2 5 do6 s random 100 7 echo e i,j t s m 1 2 8done 9done 第1行 bin bash是指此指令碼使用 bin bash來解釋執行。其中,是乙個特殊的表...