{"id":1063,"date":"2016-01-29T16:11:38","date_gmt":"2016-01-29T08:11:38","guid":{"rendered":"http:\/\/www.poloo.org\/?p=1063"},"modified":"2016-01-29T21:48:29","modified_gmt":"2016-01-29T13:48:29","slug":"centos%e9%80%9a%e8%bf%87crontab%e5%ae%9e%e7%8e%b0php%e6%89%a7%e8%a1%8c%e5%ae%9a%e6%97%b6%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=1063","title":{"rendered":"CentOS\u901a\u8fc7crontab\u5b9e\u73b0php\u6267\u884c\u5b9a\u65f6\u4efb\u52a1"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1067\" src=\"http:\/\/www.poloo.org\/uploads\/\/2016\/01\/544f0d9500017d6306000338-590-330.jpg\" alt=\"\u8ba1\u5212\u4efb\u52a1\" width=\"590\" height=\"330\" srcset=\"https:\/\/www.poloo.org\/uploads\/2016\/01\/544f0d9500017d6306000338-590-330.jpg 590w, https:\/\/www.poloo.org\/uploads\/2016\/01\/544f0d9500017d6306000338-590-330-300x168.jpg 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>\u5bf9\u4e8elinux\u6765\u8bf4\u7528crontab\u53ef\u4ee5\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u3002crontab \u53ef\u4ee5\u901a\u8fc7yum \u76f4\u63a5\u8fdb\u884c\u5b89\u88c5\u4f7f\u7528\u3002<br \/>\ncron,\u662f\u4e00\u4e2alinux\u4e0b\u7684\u5b9a\u65f6\u6267\u884c\u5de5\u5177\u3002\u6839\u7528\u6237\u4ee5\u5916\u7684\u7528\u6237\u53ef\u4ee5\u4f7f\u7528 crontab \u5de5\u5177\u6765\u914d\u7f6e cron \u4efb\u52a1\u3002\u6240\u6709\u7528\u6237\u5b9a\u4e49\u7684 crontab \u90fd\u88ab\u4fdd\u5b58\u5728\/var\/spool\/cron \u76ee\u5f55\u4e2d\uff0c\u5e76\u4f7f\u7528\u521b\u5efa\u5b83\u4eec\u7684\u7528\u6237\u8eab\u4efd\u6765\u6267\u884c\u3002\u8981\u4ee5\u67d0\u7528\u6237\u8eab\u4efd\u521b\u5efa\u4e00\u4e2a crontab \u9879\u76ee\uff0c\u767b\u5f55\u4e3a\u8be5\u7528\u6237\uff0c\u7136\u540e\u952e\u5165 crontab -e \u547d\u4ee4\u6765\u7f16\u8f91\u8be5\u7528\u6237\u7684 crontab\u3002\u8be5\u6587\u4ef6\u4f7f\u7528\u7684\u683c\u5f0f\u548c \/etc\/crontab \u76f8\u540c\u3002\u5f53\u5bf9 crontab \u6240\u505a\u7684\u6539\u53d8\u88ab\u4fdd\u5b58\u540e\uff0c\u8be5 crontab \u6587\u4ef6\u5c31\u4f1a\u6839\u636e\u8be5\u7528\u6237\u540d\u88ab\u4fdd\u5b58\uff0c\u5e76\u5199\u5165\u6587\u4ef6 \/var\/spool\/cron\/username \u4e2d\u3002cron \u5b88\u62a4\u8fdb\u7a0b\u6bcf\u5206\u949f\u90fd\u68c0\u67e5 \/etc\/crontab \u6587\u4ef6\u3001etc\/cron.d\/ \u76ee\u5f55\u3001\u4ee5\u53ca \/var\/spool\/cron \u76ee\u5f55\u4e2d\u7684\u6539\u53d8\u3002\u5982\u679c\u53d1\u73b0\u4e86\u6539\u53d8\uff0c\u5b83\u4eec\u5c31\u4f1a\u88ab\u8f7d\u5165\u5185\u5b58\u3002\u8fd9\u6837\uff0c\u5f53\u67d0\u4e2a crontab \u6587\u4ef6\u6539\u53d8\u540e\u5c31\u4e0d\u5fc5\u91cd\u65b0\u542f\u52a8\u5b88\u62a4\u8fdb\u7a0b\u4e86\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5b89\u88c5crontab\uff1a<\/p>\n<pre class=\"brush:shell\">yum install crontab<\/pre>\n<p>crontab \u8bf4\u660e\uff1a<\/p>\n<p>\/sbin\/service crond start \/\/\u542f\u52a8\u670d\u52a1<br \/>\n\/sbin\/service crond stop \/\/\u5173\u95ed\u670d\u52a1<br \/>\n\/sbin\/service crond restart \/\/\u91cd\u542f\u670d\u52a1<br \/>\n\/sbin\/service crond reload \/\/\u91cd\u65b0\u8f7d\u5165\u914d\u7f6e<\/p>\n<p>\u67e5\u770bcrontab\u670d\u52a1\u72b6\u6001\uff1aservice crond status<br \/>\n\u624b\u52a8\u542f\u52a8crontab\u670d\u52a1\uff1aservice crond start<br \/>\n\u67e5\u770bcrontab\u670d\u52a1\u662f\u5426\u5df2\u8bbe\u7f6e\u4e3a\u5f00\u673a\u542f\u52a8\uff0c\u6267\u884c\u547d\u4ee4\uff1antsysv<br \/>\n\u52a0\u5165\u5f00\u673a\u81ea\u52a8\u542f\u52a8:<br \/>\nchkconfig \u2013level 35 crond on<\/p>\n<p>crontab \u547d\u4ee4\uff1a<\/p>\n<p>\u529f\u80fd\u8bf4\u660e\uff1a\u8bbe\u7f6e\u8ba1\u65f6\u5668\u3002<br \/>\n\u8bed\u3000\u3000\u6cd5\uff1acrontab [-u &lt;\u7528\u6237\u540d\u79f0&gt;][\u914d\u7f6e\u6587\u4ef6] \u6216 crontab [-u &lt;\u7528\u6237\u540d\u79f0&gt;][-elr]<br \/>\n\u8865\u5145\u8bf4\u660e\uff1acron\u662f\u4e00\u4e2a\u5e38\u9a7b\u670d\u52a1\uff0c\u5b83\u63d0\u4f9b\u8ba1\u65f6\u5668\u7684\u529f\u80fd\uff0c\u8ba9\u7528\u6237\u5728\u7279\u5b9a\u7684\u65f6\u95f4\u5f97\u4ee5\u6267\u884c\u9884\u8bbe\u7684\u6307\u4ee4\u6216\u7a0b\u5e8f\u3002\u53ea\u8981\u7528\u6237\u4f1a\u7f16\u8f91\u8ba1\u65f6\u5668\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u4f7f \u7528\u8ba1\u65f6\u5668\u7684\u529f\u80fd\u3002\u5176\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f\u5982\u4e0b\uff1a<br \/>\nMinute Hour Day Month DayOFWeek Command<br \/>\n\u53c2\u3000\u3000\u6570\uff1a<br \/>\n-e \u3000\u7f16\u8f91\u8be5\u7528\u6237\u7684\u8ba1\u65f6\u5668\u8bbe\u7f6e\u3002<br \/>\n-l \u3000\u5217\u51fa\u8be5\u7528\u6237\u7684\u8ba1\u65f6\u5668\u8bbe\u7f6e\u3002<br \/>\n-r \u3000\u5220\u9664\u8be5\u7528\u6237\u7684\u8ba1\u65f6\u5668\u8bbe\u7f6e\u3002<br \/>\n-u&lt;\u7528\u6237\u540d\u79f0&gt; \u3000\u6307\u5b9a\u8981\u8bbe\u5b9a\u8ba1\u65f6\u5668\u7684\u7528\u6237\u540d\u79f0\u3002<\/p>\n<p>crontab \u683c\u5f0f\uff1a<\/p>\n<p>\u57fa\u672c\u683c\u5f0f :<br \/>\n\u5206\u949f\u00a0\u00a0 \u5c0f\u65f6\u00a0\u00a0 \u65e5\u00a0\u00a0 \u6708\u00a0\u00a0 \u661f\u671f\u00a0\u00a0 \u547d\u4ee4<br \/>\n*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *<br \/>\n\u7b2c1\u5217\u8868\u793a\u5206\u949f1\uff5e59 \u6bcf\u5206\u949f\u7528*\u6216\u8005 *\/1\u8868\u793a<br \/>\n\u7b2c2\u5217\u8868\u793a\u5c0f\u65f61\uff5e23\uff080\u8868\u793a0\u70b9\uff09<br \/>\n\u7b2c3\u5217\u8868\u793a\u65e5\u671f1\uff5e31<br \/>\n\u7b2c4\u5217 \u8868\u793a\u6708\u4efd1\uff5e12<br \/>\n\u7b2c5\u5217\u6807\u8bc6\u53f7\u661f\u671f0\uff5e6\uff080\u8868\u793a\u661f\u671f\u5929\uff09<br \/>\n\u7b2c6\u5217\u8981\u8fd0\u884c\u7684\u547d\u4ee4<br \/>\n\u8bb0\u4f4f\u51e0\u4e2a\u7279\u6b8a\u7b26\u53f7\u7684\u542b\u4e49:<br \/>\n\u201c*\u201d\u4ee3\u8868\u53d6\u503c\u8303\u56f4\u5185\u7684\u6570\u5b57,<br \/>\n\u201c\/\u201d\u4ee3\u8868\u201d\u6bcf\u201d,<br \/>\n\u201c-\u201d\u4ee3\u8868\u4ece\u67d0\u4e2a\u6570\u5b57\u5230\u67d0\u4e2a\u6570\u5b57,<br \/>\n\u201c,\u201d\u5206\u5f00\u51e0\u4e2a\u79bb\u6563\u7684\u6570\u5b57<br \/>\n# Use the hash sign to prefix a comment<br \/>\n# +\u2014\u2014\u2014\u2014\u2014- minute (0 \u2013 59)<br \/>\n# | +\u2014\u2014\u2014\u2014- hour (0 \u2013 23)<br \/>\n# | | +\u2014\u2014\u2014- day of month (1 \u2013 31)<br \/>\n# | | | +\u2014\u2014- month (1 \u2013 12)<br \/>\n# | | | | +\u2014- day of week (0 \u2013 7) (Sunday=0 or 7)<br \/>\n# | | | | |<br \/>\n# * * * * * command to be executed<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>\u6bcf\u5929\u51cc\u66681\u70b920\u5206\u91cd\u542fnginx<\/p>\n<pre class=\"brush:shell\">20 1 * * * \/etc\/init.d\/nginx restart<\/pre>\n<p>\u6bcf\u5929\u65e9\u4e0a\u5341\u70b9\u6267\u884cphp\u7b7e\u5230\u4efb\u52a1\uff0c\u5e76\u5c06\u6267\u884c\u7ed3\u679c\u5199\u5165v.log<\/p>\n<pre class=\"brush:shell\">0 10 * * * \/usr\/bin\/php -f \/data\/wwwroot\/v.php &gt;&gt; \/data\/wwwroot\/v.log<\/pre>\n<p>\u6267\u884c\u7684v.php \u6587\u4ef6\u9700\u8981\u6709 x\u5c5e\u6027\uff1a<\/p>\n<pre class=\"brush:shell\">chmod +x v.php<\/pre>\n<p>\u901a\u8fc7 tail -f v.log \u53ef\u4ee5\u67e5\u770blog\u6587\u4ef6\u5b9e\u65f6\u53d8\u5316<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8elinux\u6765\u8bf4\u7528crontab\u53ef\u4ee5\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u3002crontab &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1067,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5,18],"tags":[40,45,36,175,177,176],"class_list":["post-1063","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-NetOS","category-Note","category-Php","tag-centos","tag-linux-2","tag-php-2","tag-175","tag-177","tag-176"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1063"}],"version-history":[{"count":1,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1063\/revisions"}],"predecessor-version":[{"id":1068,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1063\/revisions\/1068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/media\/1067"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}