{"id":203477,"date":"2025-05-22T13:37:01","date_gmt":"2025-05-22T05:37:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203477\/"},"modified":"2025-05-22T13:37:01","modified_gmt":"2025-05-22T05:37:01","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3nohup-log%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e5%8d%a0%e7%94%a8%e7%a9%ba%e9%97%b4%e8%bf%87%e5%a4%a7%e7%9a%84%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203477\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587\u4ef6\u5360\u7528\u7a7a\u95f4\u8fc7\u5927\u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587\u4ef6\u5360\u7528\u7a7a\u95f4\u8fc7\u5927\u7684\u95ee\u9898\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5982\u4f55\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587\u4ef6\u5360\u7528\u7a7a\u95f4\u8fc7\u5927\u7684\u95ee\u9898\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731134191672f02ef521f6.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587\u4ef6\u8fc7\u5927\u95ee\u9898<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>nohup.log\u65e5\u5fd7\u6587\u4ef6\u4fdd\u5b58\u4e86\u5927\u91cf\u63a7\u5236\u53f0\u8f93\u51fa\u5185\u5bb9\uff0c\u5bfc\u81f4\u670d\u52a1\u5668\u7a7a\u95f4\u5360\u7528\u8fc7\u5927\uff0c\u8bf7\u6c42\u63d0\u4f9b\u9650\u5236\u6587\u4ef6\u5927\u5c0f\u6216\u6c38\u4e45\u6027\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u9650\u5236nohup.log\u6587\u4ef6\u5927\u5c0f\uff1a<\/p>\n<ul>\n<li><strong>tail -n xx nohup.log<\/strong><\/li>\n<\/ul>\n<p>\u6b64\u547d\u4ee4\u5c06\u4ec5\u663e\u793a\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u540ex\u884c\uff0c\u53ef\u5c06\u5176\u5199\u5165\u811a\u672c\u4ee5\u5b9a\u671f\u6e05\u7406\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n<ul>\n<li><strong>\u4f7f\u7528logrotate\u5de5\u5177<\/strong><\/li>\n<\/ul>\n<p>logrotate\u5de5\u5177\u53ef\u4ee5\u5728\u6307\u5b9a\u65f6\u95f4\uff08\u4f8b\u5982\u6bcf\u5929\u6216\u6bcf\u5468\uff09\u81ea\u52a8\u6e05\u7406\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n<ul>\n<li><strong>\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6<\/strong><\/li>\n<\/ul>\n<p>\u5728\u542f\u52a8\u547d\u4ee4\u65f6\uff0c\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u4e0d\u662fnohup.log\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>nohup python script.py &gt; output.log 2&gt;&amp;1 &amp;<\/pre>\n<p>\u6b64\u547d\u4ee4\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230output.log\u6587\u4ef6\u4e2d\u3002<\/p>\n<ul>\n<li><strong>\u91cd\u65b0\u542f\u52a8\u5b88\u62a4\u8fdb\u7a0b<\/strong><\/li>\n<\/ul>\n<p>\u5982\u679cnohup.log\u6587\u4ef6\u662f\u5b88\u62a4\u8fdb\u7a0b\uff08\u4f8b\u5982web\u670d\u52a1\u5668\uff09\u7684\u8f93\u51fa\uff0c\u5219\u91cd\u65b0\u542f\u52a8\u5b88\u62a4\u8fdb\u7a0b\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684nohup.log\u6587\u4ef6\u3002<\/p>\n<ul>\n<li><strong>\u4f7f\u7528xargs\u547d\u4ee4<\/strong><\/li>\n<\/ul>\n<p>xargs\u547d\u4ee4\u53ef\u4ee5\u5c06\u65e5\u5fd7\u884c\u5206\u5272\u6210\u8f83\u5c0f\u7684\u5757\uff0c\u5e76\u5c06\u5176\u5199\u5165\u591a\u4e2a\u6587\u4ef6\u3002\u4ee5\u4e0b\u547d\u4ee4\u5c06\u65e5\u5fd7\u6587\u4ef6\u5206\u5272\u6210500\u884c\u7684\u5757\uff1a<\/p>\n<pre>tail -f nohup.log | xargs -n 500 cat - &gt;&gt; nohup.log.1 nohup.log.2 nohup.log.3<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587\u4ef6\u5360\u7528\u7a7a\u95f4\u8fc7\u5927\u7684\u95ee\u9898\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3nohup.log\u65e5\u5fd7\u6587&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203477","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203477"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203477\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}