{"id":284666,"date":"2023-10-05T20:12:47","date_gmt":"2023-10-05T12:12:47","guid":{"rendered":"https:\/\/lrxjmw.cn\/lsyzn.html"},"modified":"2023-10-05T20:12:47","modified_gmt":"2023-10-05T12:12:47","slug":"lsyzn","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lsyzn.html","title":{"rendered":"Linux crontab\u5b9e\u7528\u6307\u5357"},"content":{"rendered":"

\u6211\u662f\u4e00\u4f4d\u6280\u672f\u4e13\u5bb6\uff0c\u62c5\u4efb\u7cfb\u7edf<\/a>\u7ba1\u7406\u5458\u7684\u804c\u52a1\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u4ee5\u7cfb\u7edf\u7ba1\u7406\u5458\u7684\u8eab\u4efd\u4e3a\u60a8\u4ecb\u7ecdlinux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/strong>\u7684\u76f8\u5173\u77e5\u8bc6\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n

1.\u4ec0\u4e48\u662fcrontab\uff1f<\/p>\n

crontab\u662f\u4e00\u4e2a\u7528\u4e8e\u5728Linux<\/a>\u7cfb\u7edf\u4e0a\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\u7684\u547d\u4ee4<\/a>\u3002\u5b83\u5141\u8bb8\u7528\u6237\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\u81ea\u52a8\u8fd0\u884c\u811a\u672c\u3001\u547d\u4ee4\u6216\u7a0b\u5e8f\u3002<\/p>\n

2. crontab\u7684\u8bed\u6cd5<\/p>\n

crontab\u7684\u8bed\u6cd5\u975e\u5e38\u7b80\u5355linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/strong>\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

\n

\n***** command\n<\/pre>\n<\/p>\n

\u5176\u4e2dlinux\u5165\u95e8\uff0c\u4e94\u4e2a\u661f\u53f7\u5206\u522b\u4ee3\u8868\u5206\u949f\u3001\u5c0f\u65f6\u3001\u65e5\u671f\u3001\u6708\u4efd\u548c\u661f\u671f\u51e0\u3002command\u8868\u793a\u8981\u6267\u884c\u7684\u547d\u4ee4\u6216\u811a\u672c\u3002<\/p>\n

3.\u5982\u4f55\u7f16\u8f91crontab\u6587\u4ef6<\/p>\n

linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab_linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab_linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/p>\n

\u8981\u7f16\u8f91crontab\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\n

\ncrontab -e\n<\/pre>\n<\/p>\n

\u8fd9\u4f1a\u6253\u5f00\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u6dfb\u52a0\u6216\u4fee\u6539\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n

4.\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1<\/p>\n

\u8981\u6dfb\u52a0\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u53ea\u9700\u5728crontab\u6587\u4ef6\u4e2d\u65b0\u589e\u4e00\u884c\u5373\u53ef\u3002\u4f8b\u5982linux \u8bba\u575b\uff0c\u8981\u6bcf\u5929\u51cc\u66681\u70b9\u91cd\u542f\u67d0\u4e2a\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

\n

\n0 1 ***\/path\/to\/program\/restart.sh\n<\/pre>\n<\/p>\n

\u8fd9\u6837\uff0c\u6bcf\u5929\u51cc\u66681\u70b9\u65f6\uff0c\u7cfb\u7edf\u5c31\u4f1a\u81ea\u52a8\u6267\u884crestart.sh\u811a\u672c\uff0c\u4ece\u800c\u5b9e\u73b0\u7a0b\u5e8f\u7684\u91cd\u542f\u3002<\/p>\n

5.\u5220\u9664\u5b9a\u65f6\u4efb\u52a1<\/p>\n

\u5982\u679c\u60a8\u9700\u8981\u5220\u9664\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\n

\ncrontab -r\n<\/pre>\n<\/p>\n

\u8fd9\u4f1a\u5c06\u5f53\u524d\u7528\u6237\u7684\u6240\u6709\u5b9a\u65f6\u4efb\u52a1\u90fd\u5220\u9664\u3002<\/p>\n

6.\u67e5\u770b\u5b9a\u65f6\u4efb\u52a1\u5217\u8868<\/p>\n

linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab_linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab_linux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/p>\n

\u8981\u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u5b9a\u65f6\u4efb\u52a1\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\n

\ncrontab -l\n<\/pre>\n<\/p>\n

\u7cfb\u7edf\u4f1a\u663e\u793a\u51fa\u5f53\u524d\u7528\u6237\u7684\u6240\u6709\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n

7.\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u5728\u7f16\u5199\u5b9a\u65f6\u4efb\u52a1\u65f6\uff0c\u6709\u51e0\u4e2a\u6ce8\u610f\u4e8b\u9879\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n

- crontab\u6587\u4ef6\u4e2d\u6bcf\u884c\u53ea\u80fd\u6709\u4e00\u4e2a\u547d\u4ee4\uff1b<\/p>\n

-\u6bcf\u4e2a\u5b57\u6bb5\u7684\u53d6\u503c\u8303\u56f4\u662f\u56fa\u5b9a\u7684\uff0c\u4f8b\u5982\u5206\u949f\u5b57\u6bb5\u7684\u53d6\u503c\u8303\u56f4\u662f0\u523059\uff1b<\/p>\n

-\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u6765\u6307\u5b9a\u8981\u6267\u884c\u7684\u547d\u4ee4\u6216\u811a\u672clinux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/strong>\uff0c\u4ee5\u786e\u4fdd\u7cfb\u7edf\u80fd\u591f\u6b63\u786e\u627e\u5230\u5b83\u4eec\uff1b<\/p>\n

-\u5728\u7f16\u8f91crontab\u6587\u4ef6\u65f6\uff0c\u52a1\u5fc5\u5c0f\u5fc3\u8c28\u614e\uff0c\u907f\u514d\u8bef\u64cd\u4f5c\u5bfc\u81f4\u7cfb\u7edf\u6545\u969c\u3002<\/p>\n

8.\u5b9e\u4f8b\u5e94\u7528<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u9645\u5e94\u7528\u7684\u4f8b\u5b50\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u6bcf\u5468\u4e94\u665a\u4e0a10\u70b9\u5907\u4efd<\/a>\u6570\u636e\u5e93\uff1a<\/p>\n

\n

\n0 22 ** 5 \/path\/to\/backup_script.sh\n<\/pre>\n<\/p>\n

\u8fd9\u6837\uff0c\u6bcf\u5468\u4e94\u665a\u4e0a10\u70b9\uff0c\u7cfb\u7edf\u5c31\u4f1a\u81ea\u52a8\u6267\u884cbackup_script.sh\u811a\u672c\uff0c\u4ece\u800c\u5b8c\u6210\u6570\u636e\u5e93\u7684\u5907\u4efd\u5de5\u4f5c\u3002<\/p>\n

9.\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/p>\n

Q: crontab\u4efb\u52a1\u6ca1\u6709\u6309\u9884\u671f\u6267\u884c\u600e\u4e48\u529e\uff1f<\/p>\n

A:\u9996\u5148\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u6b63\u786e\u8bbe\u7f6e\u4e86\u65f6\u95f4\u548c\u547d\u4ee4\u3002\u5176\u6b21\uff0c\u8bf7\u68c0\u67e5crontab\u65e5\u5fd7\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\/var\/log\/cron\u6216\/var\/log\/syslog\uff09\uff0c\u67e5\u770b\u662f\u5426\u6709\u4efb\u4f55\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n

10.\u603b\u7ed3<\/p>\n

\u901a\u8fc7\u4f7f\u7528crontab\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f\u7684\u529f\u80fd\u3002\u65e0\u8bba\u662f\u5907\u4efd\u6570\u636e\u3001\u5b9a\u671f\u6e05\u7406\u6587\u4ef6\u8fd8\u662f\u5176\u4ed6\u4efb\u52a1\uff0ccrontab\u90fd\u80fd\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662f\u5173\u4e8elinux\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f crontab<\/strong>\u7684\u76f8\u5173\u5185\u5bb9\u4ecb\u7ecd\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

crontab\u7684\u76f8\u5173\u77e5\u8bc6\u548c\u4f7f\u7528\u65b9\u6cd5\u3002crontab\u662f\u4e00\u4e2a\u7528\u4e8e\u5728Linux\u7cfb\u7edf\u4e0a\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\u7684\u547d\u4ee4\u3002crontab\u7684\u8bed\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a\u8981\u7f16\u8f91crontab\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a\u8981\u6dfb\u52a0\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u53ea\u9700\u5728crontab\u6587\u4ef6\u4e2d\u65b0\u589e\u4e00\u884c\u5373\u53ef\u3002\u8981\u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u5b9a\u65f6\u4efb\u52a1\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a\u901a\u8fc7\u4f7f\u7528crontab\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5b9a\u65f6\u81ea\u52a8\u91cd\u542f\u7a0b\u5e8f\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":284667,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-284666","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/284666","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=284666"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/284666\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/284667"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=284666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=284666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=284666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}