{"id":155905,"date":"2019-08-27T08:35:56","date_gmt":"2019-08-27T00:35:56","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=155905"},"modified":"2019-08-16T09:36:54","modified_gmt":"2019-08-16T01:36:54","slug":"shell-share","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/shell-share.html","title":{"rendered":"\u63a8\u8350\u8d85\u8be6\u7ec6\u76845\u4e2aShell\u811a\u672c\u5b9e\u4f8b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4eca\u5929\u4e3b\u8981\u5206\u4eab5\u4e2ashell\u811a\u672c\u5b9e\u4f8b\uff0c\u5927\u5bb6\u53ef\u4ee5\u501f\u9274\u4e0b\u91cc\u9762\u7684\u601d\u8def\uff0c\u770b\u4e0b\u6709\u6ca1\u53e6\u5916\u4e00\u79cd\u5b9e\u73b0\u65b9\u5f0f\u3002 <\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

1\u3001\u5b9a\u65f6\u6e05\u7a7a\u6587\u4ef6\u5185\u5bb9\uff0c\u5b9a\u65f6\u8bb0\u5f55\u6587\u4ef6\u5927\u5c0f<\/strong><\/div>\n
#!\/bin\/bash\r\n################################################################\r\n#\u6bcf\u5c0f\u65f6\u6267\u884c\u4e00\u6b21\u811a\u672c\uff08\u4efb\u52a1\u8ba1\u5212\uff09\uff0c\u5f53\u65f6\u95f4\u4e3a0\u70b9\u621612\u70b9\u65f6\uff0c\u5c06\u76ee\u6807\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u5185\r\n#\u5bb9\u6e05\u7a7a\uff0c\u4f46\u4e0d\u5220\u9664\u6587\u4ef6\uff0c\u5176\u4ed6\u65f6\u95f4\u5219\u53ea\u7edf\u8ba1\u5404\u4e2a\u6587\u4ef6\u7684\u6253\u5c0f\uff0c\u4e00\u4e2a\u6587\u4ef6\u4e00\u884c\uff0c\u8f93\u51fa\u5230\u4ee5\u65f6#\u95f4\u548c\u65e5\u671f\u547d\u540d\u7684\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u8003\u8651\u76ee\u6807\u76ee\u5f55\u4e0b\u4e8c\u7ea7\u3001\u4e09\u7ea7\u7b49\u5b50\u76ee\u5f55\u7684\u6587\u4ef6\r\n################################################################\r\nlogfile=\/tmp\/`date +%H-%F`.log\r\nn=`date +%H`\r\nif [ $n -eq 00 ] || [ $n -eq 12 ]\r\nthen\r\n#\u901a\u8fc7for\u5faa\u73af\uff0c\u4ee5find\u547d\u4ee4\u4f5c\u4e3a\u904d\u5386\u6761\u4ef6\uff0c\u5c06\u76ee\u6807\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u8fdb\u884c\u904d\u5386\u5e76\u505a\u76f8\u5e94\u64cd\u4f5c\r\nfor i in `find \/data\/log\/ -type f`\r\ndo\r\ntrue > $i\r\ndone\r\nelse\r\nfor i in `find \/data\/log\/ -type f`\r\ndo\r\ndu -sh $i >> $logfile\r\ndone\r\nfi\r\n<\/pre>\n

\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n

\"\"<\/p>\n

2\u3001\u8ba1\u7b97\u6587\u6863\u6bcf\u884c\u51fa\u73b0\u7684\u6570\u5b57\u4e2a\u6570\uff0c\u5e76\u8ba1\u7b97\u6574\u4e2a\u6587\u6863\u7684\u6570\u5b57\u603b\u6570<\/strong><\/div>\n
#!\/bin\/bash\r\n#########################################################\r\n#\u8ba1\u7b97\u6587\u6863\u6bcf\u884c\u51fa\u73b0\u7684\u6570\u5b57\u4e2a\u6570\uff0c\u5e76\u8ba1\u7b97\u6574\u4e2a\u6587\u6863\u7684\u6570\u5b57\u603b\u6570\r\n########################################################\r\n#\u4f7f\u7528awk\u53ea\u8f93\u51fa\u6587\u6863\u884c\u6570\uff08\u622a\u53d6\u7b2c\u4e00\u6bb5\uff09\r\nn=`wc -l a.txt|awk '{print $1}'`\r\nsum=0\r\n#\u6587\u6863\u4e2d\u6bcf\u4e00\u884c\u53ef\u80fd\u5b58\u5728\u7a7a\u683c\uff0c\u56e0\u6b64\u4e0d\u80fd\u76f4\u63a5\u7528\u6587\u6863\u5185\u5bb9\u8fdb\u884c\u904d\u5386\r\nfor i in `seq 1 $n`\r\ndo\r\n#\u8f93\u51fa\u7684\u884c\u7528\u53d8\u91cf\u8868\u793a\u65f6\uff0c\u9700\u8981\u7528\u53cc\u5f15\u53f7\r\nline=`sed -n \"$i\"p a.txt`\r\n#wc -L\u9009\u9879\uff0c\u7edf\u8ba1\u6700\u957f\u884c\u7684\u957f\u5ea6\r\nn_n=`echo $line|sed s'\/[^0-9]\/\/'g|wc -L`\r\necho $n_n\r\nsum=$[$sum+$n_n]\r\ndone\r\necho \"sum:$sum\"\r\n<\/pre>\n

\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf
\n\"\"
\n\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n

\"\"<\/p>\n

3\u3001\u68c0\u6d4b\u4e24\u53f0\u670d\u52a1\u5668\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u4e00\u81f4\u6027<\/strong><\/div>\n
#!\/bin\/bash\r\n#####################################\r\n#\u68c0\u6d4b\u4e24\u53f0\u670d\u52a1\u5668\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u4e00\u81f4\u6027\r\n#####################################\r\n#\u901a\u8fc7\u5bf9\u6bd4\u4e24\u53f0\u670d\u52a1\u5668\u4e0a\u6587\u4ef6\u7684md5\u503c\uff0c\u8fbe\u5230\u68c0\u6d4b\u4e00\u81f4\u6027\u7684\u76ee\u7684\r\ndir=\/data\/web\r\nb_ip=192.168.88.10\r\n#\u5c06\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u5168\u90e8\u904d\u5386\u51fa\u6765\u5e76\u4f5c\u4e3amd5sum\u547d\u4ee4\u7684\u53c2\u6570\uff0c\u8fdb\u800c\u5f97\u5230\u6240\u6709\u6587\u4ef6\u7684md5\u503c\uff0c\u5e76\u5199\u5165\u5230\u6307\u5b9a\u6587\u4ef6\u4e2d\r\nfind $dir -type f|xargs md5sum > \/tmp\/md5_a.txt\r\nssh $b_ip \"find $dir -type f|xargs md5sum > \/tmp\/md5_b.txt\"\r\nscp $b_ip:\/tmp\/md5_b.txt \/tmp\r\n#\u5c06\u6587\u4ef6\u540d\u4f5c\u4e3a\u904d\u5386\u5bf9\u8c61\u8fdb\u884c\u4e00\u4e00\u6bd4\u5bf9\r\nfor f in `awk '{print 2} \/tmp\/md5_a.txt'`\r\ndo\r\n#\u4ee5a\u673a\u5668\u4e3a\u6807\u51c6\uff0c\u5f53b\u673a\u5668\u4e0d\u5b58\u5728\u904d\u5386\u5bf9\u8c61\u4e2d\u7684\u6587\u4ef6\u65f6\u76f4\u63a5\u8f93\u51fa\u4e0d\u5b58\u5728\u7684\u7ed3\u679c\r\nif grep -qw \"$f\" \/tmp\/md5_b.txt\r\nthen\r\nmd5_a=`grep -w \"$f\" \/tmp\/md5_a.txt|awk '{print 1}'`\r\nmd5_b=`grep -w \"$f\" \/tmp\/md5_b.txt|awk '{print 1}'`\r\n#\u5f53\u6587\u4ef6\u5b58\u5728\u65f6\uff0c\u5982\u679cmd5\u503c\u4e0d\u4e00\u81f4\u5219\u8f93\u51fa\u6587\u4ef6\u6539\u53d8\u7684\u7ed3\u679c\r\nif [ $md5_a != $md5_b ]\r\nthen\r\necho \"$f changed.\"\r\nfi\r\nelse\r\necho \"$f deleted.\"\r\nfi\r\ndone<\/pre>\n

\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n

\"\"<\/p>\n

4\u3001\u68c0\u6d4b\u7f51\u5361\u6d41\u91cf\uff0c\u5e76\u6309\u89c4\u5b9a\u683c\u5f0f\u8bb0\u5f55\u5728\u65e5\u5fd7\u4e2d<\/strong><\/div>\n
#!\/bin\/bash\r\n#######################################################\r\n#\u68c0\u6d4b\u7f51\u5361\u6d41\u91cf\uff0c\u5e76\u6309\u89c4\u5b9a\u683c\u5f0f\u8bb0\u5f55\u5728\u65e5\u5fd7\u4e2d\r\n#\u89c4\u5b9a\u4e00\u5206\u949f\u8bb0\u5f55\u4e00\u6b21\r\n#\u65e5\u5fd7\u683c\u5f0f\u5982\u4e0b\u6240\u793a:\r\n#2019-08-12 20:40\r\n#ens33 input: 1234bps\r\n#ens33 output: 1235bps\r\n######################################################3\r\nwhile :\r\ndo\r\n#\u8bbe\u7f6e\u8bed\u8a00\u4e3a\u82f1\u6587\uff0c\u4fdd\u969c\u8f93\u51fa\u7ed3\u679c\u662f\u82f1\u6587\uff0c\u5426\u5219\u4f1a\u51fa\u73b0bug\r\nLANG=en\r\nlogfile=\/tmp\/`date +%d`.log\r\n#\u5c06\u4e0b\u9762\u6267\u884c\u7684\u547d\u4ee4\u7ed3\u679c\u8f93\u51fa\u91cd\u5b9a\u5411\u5230logfile\u65e5\u5fd7\u4e2d\r\nexec >> $logfile\r\ndate +\"%F %H:%M\"\r\n#sar\u547d\u4ee4\u7edf\u8ba1\u7684\u6d41\u91cf\u5355\u4f4d\u4e3akb\/s\uff0c\u65e5\u5fd7\u683c\u5f0f\u4e3abps\uff0c\u56e0\u6b64\u8981*1000*8\r\nsar -n DEV 1 59|grep Average|grep ens33|awk '{print $2,\"\\t\",\"input:\",\"\\t\",$5*1000*8,\"bps\",\"\\n\",$2,\"\\t\",\"output:\",\"\\t\",$6*1000*8,\"bps\"}'\r\necho \"####################\"\r\n#\u56e0\u4e3a\u6267\u884csar\u547d\u4ee4\u9700\u898159\u79d2\uff0c\u56e0\u6b64\u4e0d\u9700\u8981sleep\r\ndone\r\n<\/pre>\n

\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n

\"\"<\/p>\n

\u8f93\u51fa\u7ed3\u679c\uff1a
\n\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n

\"\"<\/p>\n

5\u3001\u6740\u6b7b\u6240\u6709\u811a\u672c<\/strong><\/div>\n
#!\/bin\/bash\r\n################################################################\r\n#\u6709\u4e00\u4e9b\u811a\u672c\u52a0\u5165\u5230\u4e86cron\u4e4b\u4e2d\uff0c\u5b58\u5728\u811a\u672c\u5c1a\u672a\u8fd0\u884c\u5b8c\u6bd5\u53c8\u6709\u65b0\u4efb\u52a1\u9700\u8981\u6267\u884c\u7684\u60c5\u51b5\uff0c\r\n#\u5bfc\u81f4\u7cfb\u7edf\u8d1f\u8f7d\u5347\u9ad8\uff0c\u56e0\u6b64\u53ef\u901a\u8fc7\u7f16\u5199\u811a\u672c\uff0c\u7b5b\u9009\u51fa\u5f71\u54cd\u8d1f\u8f7d\u7684\u8fdb\u7a0b\u4e00\u6b21\u6027\u5168\u90e8\u6740\u6b7b\u3002\r\n################################################################\r\nps aux|grep \u6307\u5b9a\u8fdb\u7a0b\u540d|grep -v grep|awk '{print $2}'|xargs kill -9<\/pre>\n

\u8d85\u8be6\u7ec6\u76845\u4e2ashell\u811a\u672c\u5b9e\u4f8b\u5206\u4eab\uff0c\u503c\u5f97\u6536\u85cf<\/p>\n","protected":false},"excerpt":{"rendered":"

#!\/bin\/bash ########################################### […]<\/p>\n","protected":false},"author":1469,"featured_media":155913,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-155905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/155905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=155905"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/155905\/revisions"}],"predecessor-version":[{"id":156006,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/155905\/revisions\/156006"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/155913"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=155905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=155905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=155905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}