\u5982\u56fe\u6240\u793a\uff0c\u6240\u6709 cron \u4efb\u52a1\u6587\u4ef6\u90fd\u5e26\u6709\u91ca\u4f34shebang\u6807\u5934\u3002<\/p>\n
#!\/bin\/bash<\/pre>\n\u8fd9\u8868\u793a\u4f60\u6b63\u5728\u4f7f\u7528\u7684 shell\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5373 bash shell\u3002<\/p>\n
\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u6211\u4eec\u4e4b\u524d\u6307\u5b9a\u7684 cron \u4efb\u52a1\u6761\u76ee\u6307\u5b9a\u8981\u5b89\u6392\u4efb\u52a1\u7684\u65f6\u95f4\u95f4\u9694\u3002<\/p>\n
\u8981\u6bcf\u5929\u4e0b\u5348 12:30 \u91cd\u542f\u7cfb\u7edf\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n
30 12 * * * \/sbin\/reboot<\/pre>\n\u8981\u5b89\u6392\u5728\u51cc\u6668 4:00 \u91cd\u542f\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n
0 4 * * * \/sbin\/reboot<\/pre>\n\u6ce8\uff1a\u661f\u53f7 * \u7528\u4e8e\u5339\u914d\u6240\u6709\u8bb0\u5f55\u3002<\/p>\n
\u8981\u6bcf\u5929\u4e24\u6b21\u8fd0\u884c\u811a\u672c\uff08\u4f8b\u5982\uff0c\u51cc\u6668 4:00 \u548c\u4e0b\u5348 4:00\uff09\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n
0 4,16 * * * \/path\/to\/script<\/pre>\n\u8981\u5b89\u6392 cron \u4efb\u52a1\u5728\u6bcf\u4e2a\u661f\u671f\u4e94\u4e0b\u5348 5:00 \u8fd0\u884c\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n
0 17 * * Fri \/path\/to\/script<\/pre>\n\u6216<\/p>\n
0 17 * * * 5 \/path\/to\/script<\/pre>\n\u5982\u679c\u4f60\u5e0c\u671b\u6bcf 30 \u5206\u949f\u8fd0\u884c\u4e00\u6b21 cron \u4efb\u52a1\uff0c\u8bf7\u4f7f\u7528\uff1a<\/p>\n
*\/30 * * * * \/path\/to\/script<\/pre>\n\u8981\u5b89\u6392 cron \u4efb\u52a1\u6bcf 5 \u5c0f\u65f6\u8fd0\u884c\u4e00\u6b21\uff0c\u8bf7\u8fd0\u884c\uff1a<\/p>\n
* *\/5 * * * \/path\/to\/script<\/pre>\n\u8981\u5728\u9009\u5b9a\u7684\u65e5\u671f\uff08\u4f8b\u5982\uff0c\u661f\u671f\u4e09\u548c\u661f\u671f\u4e94\u7684\u4e0b\u5348 6:00\uff09\u8fd0\u884c\u811a\u672c\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n
0 18 * * wed,fri \/path\/to\/script<\/pre>\n\u8981\u4f7f\u7528\u5355\u4e2a cron \u4efb\u52a1\u8fd0\u884c\u591a\u4e2a\u547d\u4ee4\uff0c\u8bf7\u4f7f\u7528\u5206\u53f7\u5206\u9694\u4efb\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n
* * * * * \/path\/to\/script1 ; \/path\/to\/script2<\/pre>\n\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26\u4e32\u8282\u7701\u7f16\u5199 cron \u4efb\u52a1\u7684\u65f6\u95f4
\n\u67d0\u4e9b cron \u4efb\u52a1\u53ef\u4ee5\u4f7f\u7528\u5bf9\u5e94\u4e8e\u7279\u5b9a\u65f6\u95f4\u95f4\u9694\u7684\u7279\u6b8a\u5b57\u7b26\u4e32\u8f7b\u677e\u914d\u7f6e\u3002\u4f8b\u5982\uff0c<\/p>\n
1\uff09@hourly \u65f6\u95f4\u6233\u7b49\u6548\u4e8e 0 * * * *<\/p>\n
\u5b83\u5c06\u5728\u6bcf\u5c0f\u65f6\u7684\u7b2c\u4e00\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\u3002<\/p>\n
@hourly \/path\/to\/script<\/pre>\n2\uff09@daily \u65f6\u95f4\u6233\u7b49\u6548\u4e8e 0 0 * * *<\/p>\n
\u5b83\u5728\u6bcf\u5929\u7684\u7b2c\u4e00\u5206\u949f\uff08\u5348\u591c\uff09\u6267\u884c\u4efb\u52a1\u3002\u5b83\u53ef\u4ee5\u5728\u6267\u884c\u65e5\u5e38\u5de5\u4f5c\u65f6\u6d3e\u4e0a\u7528\u573a\u3002<\/p>\n
@daily \/path\/to\/script<\/pre>\n3\uff09@weekly \u65f6\u95f4\u6233\u7b49\u6548\u4e8e 0 0 * * 0<\/p>\n
\u5b83\u5728\u6bcf\u5468\u7684\u7b2c\u4e00\u5206\u949f\u6267\u884c cron \u4efb\u52a1\uff0c\u4e00\u5468\u7b2c\u4e00\u5929\u662f\u4ece\u661f\u671f\u65e5\u5f00\u59cb\u7684\u3002<\/p>\n
@weekly \/path\/to\/script<\/pre>\n3\uff09@monthly \u65f6\u95f4\u6233\u7b49\u6548\u4e8e 0 0 1 * *<\/p>\n
\u5b83\u5728\u6bcf\u6708\u7b2c\u4e00\u5929\u7684\u7b2c\u4e00\u5206\u949f\u6267\u884c\u4efb\u52a1\u3002<\/p>\n
@monthly \/path\/to\/script<\/pre>\n4\uff09@yearly \u65f6\u95f4\u6233\u7b49\u6548\u4e8e 0 0 1 1 *<\/p>\n
\u5b83\u5728\u6bcf\u5e74\u7684\u7b2c\u4e00\u5206\u949f\u6267\u884c\u4efb\u52a1\uff0c\u53ef\u4ee5\u7528\u4e8e\u53d1\u9001\u65b0\u5e74\u95ee\u5019\u3002<\/p>\n
@yearly \/path\/to\/script<\/pre>\n\u9650\u5236 crontab<\/strong><\/div>\n\u4f5c\u4e3a Linux \u7528\u6237\uff0c\u4f60\u53ef\u4ee5\u63a7\u5236\u8c01\u6709\u6743\u4f7f\u7528 crontab \u547d\u4ee4\u3002\u53ef\u4ee5\u4f7f\u7528 \/etc\/cron.deny \u548c \/etc\/cron.allow \u6587\u4ef6\u6765\u63a7\u5236\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u4e00\u4e2a \/etc\/cron.deny \u6587\u4ef6\uff0c\u5e76\u4e14\u4e0d\u5305\u542b\u4efb\u4f55\u6761\u76ee\u3002\u8981\u9650\u5236\u7528\u6237\u4f7f\u7528 crontab \u5b9e\u7528\u7a0b\u5e8f\uff0c\u53ea\u9700\u5c06\u7528\u6237\u7684\u7528\u6237\u540d\u6dfb\u52a0\u5230\u8be5\u6587\u4ef6\u4e2d\u5373\u53ef\u3002\u5f53\u7528\u6237\u6dfb\u52a0\u5230\u8be5\u6587\u4ef6\u4e2d\uff0c\u5e76\u4e14\u8be5\u7528\u6237\u5c1d\u8bd5\u8fd0\u884c crontab \u547d\u4ee4\u65f6\uff0c\u4ed6\/\u5979\u5c06\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\u3002<\/p>\n
restricted-cron-user\r\n\r\nrestricted-cron-user<\/pre>\n\u8981\u5141\u8bb8\u7528\u6237\u7ee7\u7eed\u4f7f\u7528 crontab \u5b9e\u7528\u7a0b\u5e8f\uff0c\u53ea\u9700\u4ece \/etc\/cron.deny \u6587\u4ef6\u4e2d\u5220\u9664\u7528\u6237\u540d\u5373\u53ef\u3002<\/p>\n
\u5982\u679c\u5b58\u5728 \/etc\/cron.allow \u6587\u4ef6\uff0c\u5219\u4ec5\u6587\u4ef6\u4e2d\u5217\u51fa\u7684\u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u548c\u4f7f\u7528 crontab \u5b9e\u7528\u7a0b\u5e8f\u3002<\/p>\n
\u5982\u679c\u4e24\u4e2a\u6587\u4ef6\u90fd\u4e0d\u5b58\u5728\uff0c\u5219\u53ea\u6709 root \u7528\u6237\u5177\u6709\u4f7f\u7528 crontab \u547d\u4ee4\u7684\u7279\u6743\u3002<\/p>\n
\u5907\u4efd crontab \u6761\u76ee<\/strong><\/div>\n\u59cb\u7ec8\u5efa\u8bae\u4f60\u5907\u4efd crontab \u6761\u76ee\u3002\u4e3a\u6b64\uff0c\u8bf7\u4f7f\u7528\u8bed\u6cd5\uff1a<\/p>\n
# crontab -l > \/path\/to\/file.txt<\/pre>\n\u4f8b\u5982\uff1a<\/p>\n
# crontab -l > \/home\/james\/backup.txt<\/pre>\n\u68c0\u67e5 cron \u65e5\u5fd7<\/strong><\/div>\ncron \u65e5\u5fd7\u5b58\u50a8\u5728 \/var\/log\/cron \u6587\u4ef6\u4e2d\u3002\u8981\u67e5\u770b cron \u65e5\u5fd7\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n
# cat \/var\/log\/cron\r\nview-cron-log-files-linux\r\n\r\nview-cron-log-files-linux<\/pre>\n\u8981\u5b9e\u65f6\u67e5\u770b\u65e5\u5fd7\uff0c\u8bf7\u4f7f\u7528 tail \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
# tail -f \/var\/log\/cron\r\nview-live-cron-logs\r\n\r\nview-live-cron-logs<\/pre>\n\u603b\u7ed3<\/strong><\/div>\n\u5728\u672c\u6307\u5357\u4e2d\uff0c\u4f60\u5b66\u4e60\u4e86\u5982\u4f55\u521b\u5efa cron \u4efb\u52a1\u4ee5\u81ea\u52a8\u6267\u884c\u91cd\u590d\u6027\u4efb\u52a1\uff0c\u5982\u4f55\u5907\u4efd\u548c\u67e5\u770b cron \u65e5\u5fd7\u3002\u6211\u4eec\u5e0c\u671b\u672c\u6587\u63d0\u4f9b\u6709\u5173 cron \u4f5c\u4e1a\u7684\u6709\u7528\u89c1\u89e3\u3002\u8bf7\u968f\u65f6\u5206\u4eab\u4f60\u7684\u53cd\u9988\u548c\u610f\u89c1\u3002<\/p>\n
via: https:\/\/www.linuxtechi.com\/schedule-automate-tasks-linux-cron-jobs\/<\/p>\n
\u4f5c\u8005\uff1aPradeep Kumar \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1awxy \u6821\u5bf9\uff1awxy<\/p>\n
\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"
crontab \u5373 \u201ccron table\u201d\uff0c\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u672c\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u6307\u5b9a\u4efb\u52a1\u6267\u884c\u65f6\u95f4\u95f4\u9694\u7684\u89c4\u5219\u548c\u547d\u4ee4\u3002 […]<\/p>\n","protected":false},"author":1482,"featured_media":33406,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-165355","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\/165355","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\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=165355"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165355\/revisions"}],"predecessor-version":[{"id":165373,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165355\/revisions\/165373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/33406"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=165355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=165355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=165355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}