{"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 \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 <\/p>\n \u8981\u7f16\u8f91crontab\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n \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 \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 \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 <\/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 \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\n***** command\n<\/pre>\n<\/p>\n
\ncrontab -e\n<\/pre>\n<\/p>\n
\n0 1 ***\/path\/to\/program\/restart.sh\n<\/pre>\n<\/p>\n
\ncrontab -r\n<\/pre>\n<\/p>\n
\ncrontab -l\n<\/pre>\n<\/p>\n