shell常用脚本
前言
网上收集整理,感谢老男孩及各路大神,经常看他们的博客和视频,脚本绝对是自己纯手打,有什么不足之处,还请各位大神指点。若觉得有侵权地方,请及时联系本人,本人立即删除!!
再次感谢老男孩,虽然没报您的学习班,但是看过好多您出的视频和您的博客。人要懂得感恩,尽管不是您的学生!
部分题目链接:http://oldboy.blog.51cto.com/2561410/1632876
在/chbo/目录下批量创建以10个随机小写字母开头_固定字符串.html文件
[root@web]#catcreate_chbo.sh#!/bin/shrandpw(){</dev/urandomtr-dca-z|head-c${1:-10};echo;}[!-d/chbo]&&mkdir-p/chboforiin`seq9`doresult=`randpw`touch/chbo/${result}_chbo.htmldone[root@web]#shcreate_chbo.sh3[root@web]#ls/chbo/arwyievjgn_chbo.htmleoxtksdqhl_chbo.htmljbtpvjadia_chbo.htmlbzkhbwtgmw_chbo.htmlhhrptuucgr_chbo.htmlmmfrghunuv_chbo.htmldldpbwhdfz_chbo.htmlivfeekbiyf_chbo.htmluwqcaynijh_chbo.html
2. 批量改名,将上面文件中的chbo改为chboy
[root@webmianshi]#shchname.sh[root@webmianshi]#ls/chbo/arwyievjgn_chboy.htmleoxtksdqhl_chboy.htmljbtpvjadia_chboy.htmlbzkhbwtgmw_chboy.htmlhhrptuucgr_chboy.htmlmmfrghunuv_chboy.htmldldpbwhdfz_chboy.htmlivfeekbiyf_chboy.htmluwqcaynijh_chboy.html[root@webmianshi]#catchname.sh#!/bin/shcd/chboforfin`ls*.html`domv$f`echo$f|sed's#\(.*\)_chbo.html#\1_chboy.html#g'`done
3.批量创建用户chbo01-chbo10,并给每个用户设定8位数的随机密码。
[root@web]#catcreat_user.sh2#!/bin/sh[!-d/chbo/]&&mkdir-p/chbo/[-f/chbo/passwd]&&rm-f/chbo/passwdforiin`seq-w110`dopassword=`opensslrand-base646`useraddchbo$i&&echo$password|passwd--stdinchbo$iecho"chbo$i$password">>/chbo/passwddone[root@web]#shcreat_user.sh2Changingpasswordforuserchbo01.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo02.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo03.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo04.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo05.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo06.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo07.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo08.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo09.passwd:allauthenticationtokensupdatedsuccessfully.Changingpasswordforuserchbo10.passwd:allauthenticationtokensupdatedsuccessfully.[root@web]#cat/chbo/passwdchbo01Llkl7shdchbo0229/JqICqchbo037/0puAlTchbo04MR6mDzqEchbo05hMureKFpchbo06WpQar93pchbo07u4v0Dx+3chbo08OY5FBbgychbo09JvCGq32Dchbo108BDfbxvT[root@webmianshi]#su-chbo01[chbo01@web~]$su-chbo07Password:[chbo07@web~]$logout[chbo01@web~]$logout[root@web]#
批量删除
foriin`seq-w110`;douserdel-rchbo$i;done
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。