您好,登錄后才能下訂單哦!
前言
網(wǎng)上收集整理,感謝老男孩及各路大神,經(jīng)??此麄兊牟┛秃鸵曨l,腳本絕對是自己純手打,有什么不足之處,還請各位大神指點。若覺得有侵權(quán)地方,請及時聯(lián)系本人,本人立即刪除??!
再次感謝老男孩,雖然沒報您的學(xué)習(xí)班,但是看過好多您出的視頻和您的博客。人要懂得感恩,盡管不是您的學(xué)生!
部分題目鏈接:http://oldboy.blog.51cto.com/2561410/1632876
在/chbo/目錄下批量創(chuàng)建以10個隨機小寫字母開頭_固定字符串.html文件
[root@web ]# cat create_chbo.sh #!/bin/sh randpw(){ < /dev/urandom tr -dc a-z | head -c${1:-10}; echo; } [ ! -d /chbo ]&& mkdir -p /chbo for i in `seq 9` do result=`randpw` touch /chbo/${result}_chbo.html done [root@web ]# sh create_chbo.sh3 [root@web ]# ls /chbo/ arwyievjgn_chbo.html eoxtksdqhl_chbo.html jbtpvjadia_chbo.html bzkhbwtgmw_chbo.html hhrptuucgr_chbo.html mmfrghunuv_chbo.html dldpbwhdfz_chbo.html ivfeekbiyf_chbo.html uwqcaynijh_chbo.html
2. 批量改名,將上面文件中的chbo改為chboy
[root@web mianshi]# sh chname.sh [root@web mianshi]# ls /chbo/ arwyievjgn_chboy.html eoxtksdqhl_chboy.html jbtpvjadia_chboy.html bzkhbwtgmw_chboy.html hhrptuucgr_chboy.html mmfrghunuv_chboy.html dldpbwhdfz_chboy.html ivfeekbiyf_chboy.html uwqcaynijh_chboy.html [root@web mianshi]# cat chname.sh #!/bin/sh cd /chbo for f in `ls *.html` do mv $f `echo $f|sed 's#\(.*\)_chbo.html#\1_chboy.html#g'` done
3.批量創(chuàng)建用戶chbo01-chbo10,并給每個用戶設(shè)定8位數(shù)的隨機密碼。
[root@web ]# cat creat_user.sh2 #!/bin/sh [ ! -d /chbo/ ]&& mkdir -p /chbo/ [ -f /chbo/passwd ]&& rm -f /chbo/passwd for i in `seq -w 1 10` do password=`openssl rand -base64 6` useradd chbo$i && echo $password |passwd --stdin chbo$i echo "chbo$i $password" >>/chbo/passwd done [root@web ]# sh creat_user.sh2 Changing password for user chbo01. passwd: all authentication tokens updated successfully. Changing password for user chbo02. passwd: all authentication tokens updated successfully. Changing password for user chbo03. passwd: all authentication tokens updated successfully. Changing password for user chbo04. passwd: all authentication tokens updated successfully. Changing password for user chbo05. passwd: all authentication tokens updated successfully. Changing password for user chbo06. passwd: all authentication tokens updated successfully. Changing password for user chbo07. passwd: all authentication tokens updated successfully. Changing password for user chbo08. passwd: all authentication tokens updated successfully. Changing password for user chbo09. passwd: all authentication tokens updated successfully. Changing password for user chbo10. passwd: all authentication tokens updated successfully. [root@web ]# cat /chbo/passwd chbo01 Llkl7shd chbo02 29/JqICq chbo03 7/0puAlT chbo04 MR6mDzqE chbo05 hMureKFp chbo06 WpQar93p chbo07 u4v0Dx+3 chbo08 OY5FBbgy chbo09 JvCGq32D chbo10 8BDfbxvT [root@web mianshi]# su - chbo01 [chbo01@web ~]$ su - chbo07 Password: [chbo07@web ~]$ logout [chbo01@web ~]$ logout [root@web ]#
批量刪除
for i in `seq -w 1 10`;do userdel -r chbo$i;done
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。