批量新增使用者,並設定8位隨機密碼(禁止使用for,while等迴圈)
批量新增使用者,並設定8位隨機密碼(禁止使用for,while等迴圈)
建立使用者:
[[email protected] lin]# echo oldboy{01..05}|xargs -n1
oldboy01
oldboy02
oldboy03
oldboy04
oldboy05
[[email protected] lin]# echo oldboy{01..05}|xargs -n1|awk '{print "useradd "$NF}'
useradd oldboy01
useradd oldboy02
useradd oldboy03
useradd oldboy04
useradd oldboy05
交給bash執行
[[email protected] lin]# echo oldboy{01..05}|xargs -n1|awk '{print "useradd "$NF}'|bash
設定隨機密碼
方法1:
[[email protected] lin]# echo oldboy{01..05}:$(echo $RANDOM|md5sum|cut -c 1-8)|xargs -n1
oldboy01:2ea44fb5
oldboy02:24d3d6ab
oldboy03:d524fdff
oldboy04:92e6c1e7
oldboy05:9e6830d8
方法2:
[[email protected] lin]# echo oldboy{01..05}:$((RANDOM +10000000))|xargs -n1
oldboy01:10029728
oldboy02:10003967
oldboy03:10029427
oldboy04:10021946
oldboy05:10020909
重定向到檔案
[[email protected] lin]# echo oldboy{01..05}:$((RANDOM +10000000))|xargs -n1>oldboypwd.txt
[[email protected]
oldboy01:10027086
oldboy02:10023644
oldboy03:10016532
oldboy04:10017825
oldboy05:10027238
修改密碼
[[email protected] lin]# chpasswd oldboypwd.txt