您好,登錄后才能下訂單哦!
前言
網上收集整理,感謝老男孩及各路大神,經常看他們的博客和視頻,腳本絕對是自己純手打,有什么不足之處,還請各位大神指點。若覺得有侵權地方,請及時聯系本人,本人立即刪除!!
再次感謝老男孩,雖然沒報您的學習班,但是看過好多您出的視頻和您的博客。人要懂得感恩,盡管不是您的學生!
部分題目鏈接:http://oldboy.blog.51cto.com/2561410/1632876
在/chbo/目錄下批量創建以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.批量創建用戶chbo01-chbo10,并給每個用戶設定8位數的隨機密碼。
[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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。