{"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":"
\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 |