前言
网上收集整理,感谢老男孩及各路大神,经常看他们的博客和视频,脚本绝对是自己纯手打,有什么不足之处,还请各位大神指点。若觉得有侵权地方,请及时联系本人,本人立即删除!!
再次感谢老男孩,虽然没报您的学习班,但是看过好多您出的视频和您的博客。人要懂得感恩,尽管不是您的学生!
部分题目链接: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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。