{"id":57,"date":"2013-04-25T19:30:45","date_gmt":"2013-04-25T11:30:45","guid":{"rendered":"http:\/\/coderbee.net\/?p=57"},"modified":"2013-04-26T09:41:00","modified_gmt":"2013-04-26T01:41:00","slug":"cron%e8%b0%83%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/linux\/20130425\/57","title":{"rendered":"crontab\u8c03\u5ea6"},"content":{"rendered":"<h2>\u8c03\u5ea6\u7684\u57fa\u672c\u683c\u5f0f<\/h2>\n<pre><code>\n*    *     *    *     *       cmd\n\u5206  \u65f6    \u65e5   \u6708    \u5468      \u547d\u4ee4\n\n\u7b2c1\u5217\u8868\u793a\u5206\u949f  0 - 59\uff0c\u6bcf\u5206\u949f\u7528 * \u6216\u8005 *\/1\u8868\u793a\u3002\n\u7b2c2\u5217\u8868\u793a\u5c0f\u65f6  0 - 23\uff0c0\u8868\u793a0\u70b9\u3002\n\u7b2c3\u5217\u8868\u793a\u65e5\u671f 1 - 31\n\u7b2c4\u5217\u8868\u793a\u6708\u4efd  1 - 12\n\u7b2c5\u5217\u8868\u793a\u661f\u671f 0 - 6, 0\u8868\u793a\u661f\u671f\u65e5\n\u7b2c6\u5217\u662f\u8981\u8fd0\u884c\u7684\u547d\u4ee4\n<\/code><\/pre>\n<p>\u6708\u548c\u5468\u7684\u5c5e\u6027\u503c\u8fd8\u53ef\u4ee5\u7528\u76f8\u5e94\u82f1\u8bed\u5355\u8bcd\u7684\u524d3\u4e2a\u5b57\u6bcd\u6765\u8868\u793a\uff0c\u5982<code>jan<\/code>\u8868\u793a\u4e00\u6708\uff0c<code>mon-wen<\/code>\u8868\u793a\u5468\u4e00\u5230\u5468\u4e09\u3002<\/p>\n<p>\u7279\u6b8a\u7b26\u53f7\uff1a<\/p>\n<ul>\n<li>\u9017\u53f7<code>,<\/code>\u6765\u5206\u9694\u591a\u4e2a\u65f6\u95f4\u503c\uff0c<\/li>\n<li><code>-<\/code> \u8868\u793a\u4e00\u4e2a\u65f6\u95f4\u8303\u56f4\uff0c<\/li>\n<li><code>*<\/code>\u8868\u793a\u8be5\u5c5e\u6027\u7684\u6240\u6709\u53d6\u503c\uff0c\u662f\u5426\u6709\u6548\u53d6\u51b3\u4e8e\u76f8\u5173\u5c5e\u6027\u7684\u503c\u3002<\/li>\n<li><code>\/n<\/code>\u4ee3\u8868\u6bcf\u9694n\u4e2a\u65f6\u95f4\u5355\u4f4d\u7684\u610f\u601d\uff0c<code>*\/5<\/code>\u8868\u793a\u6bcf\u96945\u4e2a\u5355\u4f4d\uff0c<code>1-10\/2<\/code>\u8868\u793a1\u81f310\u4e4b\u95f4\u6bcf\u96942\u4e2a\u65f6\u95f4\u5355\u4f4d\uff0c\u4e5f\u5c31\u662f1,3,5,7\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u65f6\u5c5e\u6027\u6307\u5b9a\u4e86\u5177\u4f53\u503c\uff0c\u800c\u5206\u5c5e\u6027\u662f<code>*<\/code>\u5219\u8868\u793a\u6574\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u56e0\u4e3a\u65e5\u671f\u5c5e\u6027\u4e0e\u5468\u5c5e\u6027\u90fd\u8868\u793a\u67d0\u4e00\u5929\uff0c\u4e24\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u6bd4\u8f83\u5fae\u5999\u7684\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u4e24\u4e2a\u5c5e\u6027\u90fd\u662f<code>*<\/code>\uff0c\u5f53\u7136\u662f\u6309\u6bcf\u5929\u8c03\u5ea6\u3002   <\/li>\n<li>\u5982\u679c\u4e24\u4e2a\u5c5e\u6027\u4e2d\u6709\u4e00\u4e2a\u662f\u5177\u4f53\u7684\uff0c\u5982<code>0-3<\/code>\uff0c\u53e6\u4e00\u4e2a\u662f<code>*<\/code>\uff0c\u5219\u6309\u5177\u4f53\u7684\u5c5e\u6027\u8c03\u5ea6\uff0c<code>*<\/code>\u4e0d\u518d\u8868\u793a\u6240\u6709\u53d6\u503c\u3002   <\/li>\n<li>\u5982\u679c\u4e24\u4e2a\u5c5e\u6027\u90fd\u662f\u5177\u4f53\u503c\uff0c\u5219\u6309\u4e24\u4e2a\u89c4\u5219\u8c03\u5ea6\uff0c\u90fd\u6709\u6548\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>\u4e3e\u4f8b<\/h2>\n<pre><code>\n1  0  *  *  *  cmd                   \u6bcf\u592900:01\u6267\u884ccmd\n*\/5  *  *   *   *   cmd             \u6bcf\u96945\u5206\u949f\u6267\u884ccmd\n30  4  1,15, 28  *  *  cmd        \u6bcf\u67081,15,28\u53f74:30\u6267\u884ccmd\n20   3   *   *   1-5  cmd           \u6bcf\u5468\u4e00\u81f3\u4e94 3:20\u6267\u884ccmd\n30  4  1,15  *  1-3  cmd           \u6bcf\u67081,15\u53f7\u4ee5\u53ca\u6bcf\u5468\u4e00\u5230\u4e09 4:30\u6267\u884ccmd\n0  23-6\/2,12  *  *  *  cmd       \u6bcf\u592923-6\u70b9\u6bcf\u96942\u5c0f\u65f6\u53ca12\u65f6\u6267\u884ccmd\n<\/code><\/pre>\n<h2>crontab<\/h2>\n<p>\u4f7f\u7528\u8005\uff1a\u6240\u6709\u7528\u6237\u3002<br \/>\n\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n<pre><code>\ncrontab  file  [-u user]      \u7528\u6307\u5b9a\u7684\u6587\u4ef6\u66ff\u4ee3\u6307\u5b9a\u7528\u6237\uff08\u5982\u679c\u6709\u6743\u9650\uff09\u76ee\u524d\u7684 crontab\uff0c\ncrontab  -  [-u  user]        \u7528\u6807\u51c6\u8f93\u5165\u66ff\u4ee3\u6307\u5b9a\u7528\u6237\uff08\u5982\u679c\u6709\u6743\u9650\uff09\u76ee\u524d\u7684 crontab\uff0c\ncorntab -l  [user]            \u5217\u51fa\u7528\u6237\u76ee\u524d\u7684crontab\ncorntab -e  [user]            \u7f16\u8f91\u7528\u6237\u76ee\u524d\u7684crontab\ncorntab -r  [-i]  [user]      \u5220\u9664\u7528\u6237\u76ee\u524d\u7684crontab\uff0c-i \u9009\u9879\u8868\u793a\u5220\u9664\u524d\u9700\u8981\u786e\u8ba4\u3002\n<\/code><\/pre>\n<p>crontab \u7684\u6587\u4ef6\u683c\u5f0f\uff1a  \u5206  \u65f6    \u65e5   \u6708    \u5468      \u547d\u4ee4<br \/>\n\u547d\u4ee4\u88ab\u9001\u5165sh\u6267\u884c\uff0c\u8fd9\u4e2ashell\u53ea\u6709 <code>USER,  HOME,  SHELL<\/code>\u8fd9\u4e2a\u4e09\u4e2a\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u7528\u6237\u63d0\u4ea4\u7684crontab\u662f\u7531cron\u5b88\u62a4\u8fdb\u7a0b\u6267\u884c\u7684\u3002<\/p>\n<h2>cron<\/h2>\n<p>\u662f\u4e00\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7528\u4e8e\u6267\u884c\u7528\u6237\u63d0\u4ea4\u7684crontab\u8c03\u5ea6\u547d\u4ee4\u3002\u4e00\u822c\u53ea\u6709root\u7528\u6237\u624d\u80fd\u6267\u884ccron\u548c\u67e5\u770b\u5176\u4ed6\u7528\u6237\u7684\u8c03\u5ea6\u547d\u4ee4\u3002<\/p>\n<p>\u4e00\u4e9b\u4e0e\u8c03\u5ea6\u6709\u5173\u7684\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li><code>\/etc\/crontab<\/code>  \u5b58\u653e\u7cfb\u7edf\u8fd0\u884c\u7684\u8c03\u5ea6\u7a0b\u5e8f\u3002<\/li>\n<li><code>\/etc\/cron.deny<\/code> \u8868\u793a\u4e0d\u80fd\u4f7f\u7528crontab \u547d\u4ee4\u7684\u7528\u6237\u3002<\/li>\n<li><code>\/etc\/cron.allow<\/code> \u8868\u793a\u80fd\u4f7f\u7528crontab\u7684\u7528\u6237\u3002<br \/>\n \u5982\u679c\u4e0a\u9762\u4e24\u4e2a\u6587\u4ef6\u540c\u65f6\u5b58\u5728\uff0c\u90a3\u4e48\/etc\/cron.allow \u4f18\u5148\u3002\u5982\u679c\u4e24\u4e2a\u6587\u4ef6\u90fd\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u53ea\u6709\u8d85\u7ea7\u7528\u6237\u53ef\u4ee5\u5b89\u6392\u4f5c\u4e1a\u3002<\/li>\n<li>\u6bcf\u4e2a\u7528\u6237\u63d0\u4ea4\u7684crontab\u8c03\u5ea6\u90fd\u5b58\u653e\u5728<code>\/var\/spool\/cron\/crontabs\/<\/code>\u76ee\u5f55\u4e0b\u5728\u4e0e\u7528\u6237\u540d\u540c\u540d\u7684\u6587\u4ef6\u91cc\u3002<\/li>\n<\/ul>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8c03\u5ea6\u7684\u57fa\u672c\u683c\u5f0f * * * * * cmd \u5206 \u65f6 \u65e5 \u6708 \u5468 \u547d\u4ee4 \u7b2c1\u5217\u8868\u793a &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/linux\/20130425\/57\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[21,22],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":8,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":65,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions\/65"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}