{"id":290,"date":"2018-05-29T17:07:40","date_gmt":"2018-05-29T09:07:40","guid":{"rendered":"https:\/\/wp.yaanren.win\/?p=290"},"modified":"2018-05-29T17:07:40","modified_gmt":"2018-05-29T09:07:40","slug":"ubuntu-16-04%e8%ae%be%e7%bd%aecrontab%e5%ae%9a%e6%97%b6%e8%ae%a1%e5%88%92%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/wp.625300.xyz\/?p=290","title":{"rendered":"Ubuntu 16.04\u8bbe\u7f6ecrontab\u5b9a\u65f6\u8ba1\u5212\u4efb\u52a1"},"content":{"rendered":"<p>cron\u662fLinux\u4e0b\u7684\u65e0\u56fe\u5f62\u754c\u9762\u7684\u8ba1\u5212\u4efb\u52a1\u5de5\u5177\uff0c\u5bf9Linux\u8fd0\u7ef4\u81ea\u52a8\u5316\u5177\u6709\u6781\u5176\u91cd\u8981\u7684\u4f5c\u7528\uff0c\u4e5f\u53ef\u4ee5\u9002\u7528\u4e8eweb\u722c\u866b\u91c7\u96c6\u7c7b\u7684\u5de5\u4f5c\u3002\u5f53\u7136\uff0c\u5b83\u7684\u529f\u7528\u8fd8\u8fdc\u4e0d\u6b62\u8fd92\u4e2a\u3002\u60f3\u60f3\u5427\uff0c\u6bcf\u5929\u6211\u4eec\u91cd\u590d\u5e72\u7684\u4e8b\u60c5\u6709\u591a\u5c11\u2014\u2014\u9891\u7e41\u770b\u8bba\u575b\u56de\u5e16\u3001\u9891\u7e41\u770b\u80a1\u5e02\u884c\u60c5\u3001\u5b9a\u65f6\u67e5\u90ae\u4ef6\u3001\u5b9a\u65f6\u4f11\u606f\u3001\u5b9a\u65f6\u5207\u6362\u684c\u9762\u58c1\u7eb8\u3001\u5b9a\u65f6\u5907\u4efd\u91cd\u8981\u6587\u4ef6\u3001\u5b9a\u65f6\u6e05\u7406\u7cfb\u7edf\u3001\u5b9a\u65f6\u66f4\u65b0\u7cfb\u7edf\u3001\u5b9a\u65f6\u63d0\u9192\u91cd\u8981\u4e8b\u60c5\u7b49\u7b49\u7b49\u7b49\uff0c\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u901a\u8fc7cron\u6765\u5b8c\u6210\u3002\u800cLinux\u4e0b\u4e30\u5bcc\u7684cli\u8f6f\u4ef6\u548c\u5f3a\u5927\u7684shell\u811a\u672c\u8ba9\u5b9a\u65f6\u8ba1\u5212\u5de5\u4f5c\u505a\u8d77\u6765\u90a3\u4e48\u81ea\u7136\u548c\u8f7b\u677e\u3002<\/p>\n<p>\u5728Ubuntu 16.04\u53ca\u5176\u884d\u751f\u7248\u672c\u5982LinuxMint 18.1\u91cc\u5f00\u542fcron\u5b9a\u65f6\u8ba1\u5212\u4efb\u52a1\u6b65\u9aa4\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n<p>1\u3001\u5b89\u88c5cronie<\/p>\n<p>apt install cron<\/p>\n<p>2\u3001\u5f00\u901a\u5e76\u5f00\u542fcronie\u540e\u53f0\u670d\u52a1<\/p>\n<p>sudo systemctl enable cron.service; sudo systemctl start cron.service<\/p>\n<p>3\u3001\u5efa\u7acb\u4e00\u4e2aMyCrontab\uff08\u540d\u5b57\u53ef\u4ee5\u968f\u4fbf\u53d6\uff09\u7684\u6587\u4ef6\u5e76\u7f16\u8f91\u4e4b\u3002<\/p>\n<p>touch ~\/MyCrontab &amp;&amp; nano ~\/MyCrontab<\/p>\n<p>\u53c2\u8003\u4e0b\u9762\u7684\u300acrontab\u5199\u6cd5\u4e3e\u4f8b\u300b\u4ecb\u7ecd\u6765\u7f16\u8f91\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>4\u3001\u8f7d\u5165MyCrontab\u8ba1\u5212\u5230cron\u670d\u52a1\u6a21\u5757\u4e2d<\/p>\n<p>crontab ~\/MyCrontab<\/p>\n<p>5\u3001\u67e5\u770bcrontab\u8ba1\u5212\uff0c\u770b\u770b\u662f\u5426\u4e00\u5207\u5c31\u7eea<\/p>\n<p>crontab -l<\/p>\n<p>\u5173\u4e8ecrontab\u7684\u7528\u6237\u6743\u9650\uff1a<\/p>\n<p>cron\u662f\u5206\u7528\u6237\u7684\uff0c\u7cfb\u7edf\u7ea7\u522b\u7684\u547d\u4ee4\uff08\u5982\/sbin\/reboot\u7b49\uff09\u5e94\u8be5\u7528root\u8eab\u4efd\u6765\u7f16\u8f91\u548c\u8f7d\u5165crontab\u3002<br \/>\n\u670d\u52a1\u5668\u63a8\u8350\u4ee5root\u8eab\u4efd\u8bbe\u7f6ecron\uff0cLinux\u684c\u9762\u7684\u8bdd\u5c31\u7528\u666e\u901a\u7528\u6237\u3002<br \/>\n\u666e\u901a\u7528\u6237\u7684crontab\u5c31\u7b97\u666e\u901a\u7528\u6237\u4e0d\u767b\u5f55\u4e5f\u4f1a\u81ea\u52a8\u6267\u884c\u7684\u3002<br \/>\n\u4f46\u662f\u666e\u901a\u7528\u6237\u8f7d\u5165\u7684crontab\u6709mkdir \/test1\u8fd9\u6837\u7684\u53ea\u6709root\u624d\u80fd\u8fd0\u884c\u7684\u547d\u4ee4\uff0c\u90a3\u4e48\u5b83\u5c06\u4f1a\u4e0d\u6267\u884c\u3002<\/p>\n<p>\u300acrontab\u5199\u6cd5\u4e3e\u4f8b\u300b<\/p>\n<p>#&lt;\u5206\u949f&gt; &lt;\u5c0f\u65f6&gt; &lt;\u65e5&gt; &lt;\u6708\u4efd&gt; &lt;\u661f\u671f&gt; &lt;\u547d\u4ee4&gt;<\/p>\n<p>*\/1 * * * * date&gt;&gt;~\/crontest<br \/>\n#\u7528date&gt;&gt;~\/crontest\u53ef\u4ee5\u5f88\u6e05\u695a\u7684\u770b\u5230\u6d4b\u8bd5\u7684\u6548\u679c<\/p>\n<p>5 * * * * ls<br \/>\n#\u6307\u5b9a\u6bcf\u5c0f\u65f6\u7684\u7b2c5\u5206\u949f\u6267\u884c\u4e00\u6b21ls\u547d\u4ee4<\/p>\n<p>30 5 * * * \/sbin\/reboot<br \/>\n#\u6307\u5b9a\u6bcf\u5929\u7684 5:30 \u6267\u884creboot\u547d\u4ee4<\/p>\n<p>30 7 8 * * ls<br \/>\n#\u6307\u5b9a\u6bcf\u67088\u53f7\u76847\uff1a30\u5206\u6267\u884cls\u547d\u4ee4<\/p>\n<p>30 5 8 6 * ls<br \/>\n#\u6307\u5b9a\u6bcf\u5e74\u76846\u67088\u65e55\uff1a30\u6267\u884cls\u547d\u4ee4<\/p>\n<p>30 6 * * 0 ls<br \/>\n#\u6307\u5b9a\u6bcf\u661f\u671f\u65e5\u76846:30\u6267\u884cls\u547d\u4ee4\u3010\u6ce8\uff1a0\u8868\u793a\u661f\u671f\u5929\uff0c1\u8868\u793a\u661f\u671f1\u3002\u661f\u671f\u4e5f\u53ef\u4ee5\u7528\u82f1\u6587\u6765\u8868\u793a\uff0csun\u8868\u793a\u661f\u671f\u5929\uff0cmon\u8868\u793a\u661f\u671f\u4e00\u7b49\u3002\u3011<\/p>\n<p>30 3 10,20 * * ls<br \/>\n#\u6bcf\u670810\u53f7\u53ca20\u53f7\u76843\uff1a30\u6267\u884cls\u547d\u4ee4\u3010\u6ce8\uff1a\u201c,\u201d\u7528\u6765\u8fde\u63a5\u591a\u4e2a\u4e0d\u8fde\u7eed\u7684\u65f6\u6bb5\u3011<\/p>\n<p>25 8-11 * * * ls<br \/>\n#\u6bcf\u59298-11\u70b9\u7684\u7b2c25\u5206\u949f\u6267\u884cls\u547d\u4ee4\u3010\u6ce8\uff1a\u201c-\u201d\u7528\u6765\u8fde\u63a5\u8fde\u7eed\u7684\u65f6\u6bb5\u3011<\/p>\n<p>*\/15 * * * * ls<br \/>\n#\u6bcf15\u5206\u949f\u6267\u884c\u4e00\u6b21ls\u547d\u4ee4\u3010\u5373\u6bcf\u4e2a\u5c0f\u65f6\u7684\u7b2c0 15 30 45 60\u5206\u949f\u6267\u884cls\u547d\u4ee4\u3011<\/p>\n<p>30 6 *\/10 * * ls<br \/>\n#\u6bcf\u4e2a\u6708\u4e2d\uff0c\u6bcf\u969410\u59296:30\u6267\u884c\u4e00\u6b21ls\u547d\u4ee4\u3010\u5373\u6bcf\u6708\u76841\u300111\u300121\u300131\u65e5\u662f\u76846\uff1a30\u6267\u884c\u4e00\u6b21ls \u547d\u4ee4\u3002\u3011<\/p>\n<p>50 7 * * * root run-parts \/etc\/cron.daily<br \/>\n#\u6bcf\u59297\uff1a50\u4ee5root \u8eab\u4efd\u6267\u884c\/etc\/cron.daily\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u53ef\u6267\u884c\u6587\u4ef6\u3010\u6ce8\uff1arun-parts\u53c2\u6570\u8868\u793a\u6267\u884c\u540e\u9762\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u53ef\u6267\u884c\u6587\u4ef6\u3002\u3011<\/p>\n<p>\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<\/p>\n<p>crontab\u4e66\u5199\u6ce8\u610f\u4e8b\u9879<br \/>\ncrontab -e\u53ef\u4ee5\u7f16\u8f91cron\u8ba1\u5212\uff0c\u4f46\u8fd9\u4e2a\u53ea\u4f1a\u66f4\u6539\u5185\u5b58\u4e2d\u7684crontab\u4efb\u52a1\u3002\u6700\u597d\u5148\u7f16\u8f91\u786c\u76d8\u4e0a\u7684~\/MyCrontab\u6587\u4ef6\uff0c\u7136\u540e\u7528crontab ~\/MyCrontab\u8f7d\u5165\u3002<br \/>\n\u5982\u679c\u4e0d\u60f3\u6267\u884c\u67d0\u4e00\u884c\u8ba1\u5212\uff0c\u5c31\u5728\u884c\u9996\u7528#\u6ce8\u91ca\u6389\u3002<br \/>\n\u8fd0\u884cX\u7a0b\u5e8f\uff0c\u6bd4\u5982gedit\uff0c\u547d\u4ee4\u683c\u5f0f\u662fexport DISPLAY=:0.0;gedit\uff08\u7528env|grep DISP\u547d\u4ee4\u53ef\u4ee5\u770b\u5230DISPLAY\u7684\u540d\u79f0\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>cron\u662fLinux\u4e0b\u7684\u65e0\u56fe\u5f62\u754c\u9762\u7684\u8ba1\u5212\u4efb\u52a1\u5de5\u5177\uff0c\u5bf9Linux\u8fd0\u7ef4\u81ea\u52a8\u5316\u5177\u6709\u6781\u5176\u91cd\u8981\u7684\u4f5c\u7528\uff0c\u4e5f\u53ef\u4ee5\u9002\u7528\u4e8eweb&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-290","post","type-post","status-publish","format-standard","hentry","category-32"],"_links":{"self":[{"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=290"}],"version-history":[{"count":0,"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=\/wp\/v2\/posts\/290\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.625300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}