{"id":368,"date":"2017-08-24T14:49:02","date_gmt":"2017-08-24T06:49:02","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=368"},"modified":"2017-08-24T14:49:02","modified_gmt":"2017-08-24T06:49:02","slug":"%e5%85%b3%e4%ba%8e%e5%ae%9a%e6%97%b6%e6%89%a7%e8%a1%8c%e4%bb%bb%e5%8a%a1%ef%bc%9acrontab%e7%9a%8420%e4%b8%aa%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=368","title":{"rendered":"\u5173\u4e8e\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\uff1aCrontab\u768420\u4e2a\u4f8b\u5b50"},"content":{"rendered":"<div>\n<div>\n<h3>\u7b80\u4ecb<\/h3>\n<hr \/>\n<p>Linux crontab\u548cWindows task schedules\u975e\u5e38\u7684\u76f8\u4f3c\u3002Crontab\u53ef\u4ee5\u7528\u6765\u5728\u7cfb\u7edf\u4e2d\u5b9a\u671f\u7684\u6267\u884c\u4efb\u52a1\u3002\u6bd4\u5982\uff1a\u5199\u4e86\u4e00\u4e2a\u722c\u866b\u9700\u8981\u6bcf\u5929\u65e9\u4e0a\u516b\u70b9\u6267\u884c\uff0c\u5c31\u53ef\u4ee5\u7528\u5230Crontab;\u5b89\u88c5\u7684Tomcat\u670d\u52a1\u5668\u9700\u8981\u6bcf\u5929\u51cc\u6668\u91cd\u542f\u4e00\u6b21\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5230Crontab\u3002\u603b\u4e4b\uff0c\u51e0\u4e4e\u6240\u6709\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7Crontab\u8fd9\u4e2a\u5de5\u5177\u6765\u5b8c\u6210\u3002<\/p>\n<h3>\u5b89\u88c5<\/h3>\n<hr \/>\n<pre class=\"hljs undefined\"><code>yum install cronie`<\/code><\/pre>\n<h3>Crontab\u5728Linux\u4e0a\u7684\u7ed3\u6784<\/h3>\n<hr \/>\n<div class=\"image-package\"><img decoding=\"async\" src=\"http:\/\/upload-images.jianshu.io\/upload_images\/1156494-708aadc03b3a8d95.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1240\" data-original-src=\"http:\/\/upload-images.jianshu.io\/upload_images\/1156494-708aadc03b3a8d95.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\" \/><\/p>\n<div class=\"image-caption\">crontab\u7ed3\u6784.png<\/div>\n<\/div>\n<p>\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u4e3a\uff1a<br \/>\n[\u5206\u949f] [\u5c0f\u65f6] [\u6bcf\u6708\u7684\u67d0\u4e00\u5929] [\u6bcf\u5e74\u7684\u67d0\u4e00\u6708] [\u6bcf\u5468\u7684\u67d0\u4e00\u5929] [\u6267\u884c\u7684\u547d\u4ee4]<br \/>\n<strong>\u6ce8\u610f<\/strong>\uff1a\u8bf7\u7559\u610f\u6bcf\u4e2a\u9009\u9879\u7684\u53d6\u503c\u8303\u56f4\u3002<\/p>\n<h3>\u5982\u4f55 \u6dfb\u52a0\/\u7f16\u8f91 Crontab<\/h3>\n<hr \/>\n<ul>\n<li>\u6dfb\u52a0\u6216\u66f4\u65b0crontab\u4e2d\u7684\u547d\u4ee4\n<pre class=\"hljs undefined\"><code>crontab -e<\/code><\/pre>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7cfb\u7edf\u4f1a\u7f16\u8f91\u5f53\u524d\u767b\u5f55\u7528\u6237\u7684crontab\u547d\u4ee4\u96c6\u5408\u3002\u9700\u8981\u7f16\u8f91\u5176\u4ed6\u7528\u6237\u7684\u547d\u4ee4\u96c6\u5408\uff0c\u9700\u8981\u4f7f\u7528\u5230\u5982\u4e0b\u7684\u547d\u4ee4<\/p>\n<pre class=\"hljs undefined\"><code>crontab -u username -e<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>\u67e5\u770bCrontab\u547d\u4ee4\u96c6\u5408<\/h3>\n<hr \/>\n<ul>\n<li>\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u767b\u5f55\u7528\u6237\u7684Crontab\u547d\u4ee4\u96c6\u5408\n<pre class=\"hljs undefined\"><code>crontab -l<\/code><\/pre>\n<\/li>\n<li>\u67e5\u770b\u5176\u4ed6\u7528\u6237\u7684Crontab\u547d\u4ee4\u96c6\u5408\n<pre class=\"hljs undefined\"><code>crontab -u username -l<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>20\u4e2a\u8d85\u5b9e\u7528\u7684Crontab\u4f7f\u7528\u5b9e\u4f8b<\/h3>\n<hr \/>\n<ol>\n<li>\u6bcf\u5929 02:00 \u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 2 * * * \/bin\/sh backup.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5929 5:00\u548c17:00\u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 5,17 * * * \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1<br \/>\n\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u6bcf\u5206\u949f\u90fd\u9700\u8981\u6267\u884c\u7684\u811a\u672c(\u9ed8\u9ed8\u7684\u60f3\u5230\u4e8612306&#8211;)<\/p>\n<pre class=\"hljs undefined\"><code>* * * * *  \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5468\u65e5 17:00 \u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 17 * * sun  \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf 10min \u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>*\/10 * * * * \/scripts\/monitor.sh<\/code><\/pre>\n<\/li>\n<li>\u5728\u7279\u5b9a\u7684\u67d0\u51e0\u4e2a\u6708\u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>* * * jan,may,aug * \/script\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u5728\u7279\u5b9a\u7684\u67d0\u51e0\u5929\u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 17 * * sun,fri \/script\/scripy.sh<\/code><\/pre>\n<p>\u5728\u6bcf\u5468\u4e94\u3001\u5468\u65e5\u768417\u70b9\u6267\u884c\u4efb\u52a1<\/li>\n<li>\u5728\u67d0\u4e2a\u6708\u7684\u7b2c\u4e00\u4e2a\u5468\u65e5\u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 2 * * sun  [ $(date +%d) -le 07 ] &amp;&amp; \/script\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u56db\u4e2a\u5c0f\u65f6\u6267\u884c\u4e00\u4e2a\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 *\/4 * * * \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5468\u4e00\u3001\u5468\u65e5\u6267\u884c\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>0 4,17 * * sun,mon \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u4e2a30\u79d2\u6267\u884c\u4e00\u6b21\u4efb\u52a1<br \/>\n\u6211\u4eec\u6ca1\u6709\u529e\u6cd5\u76f4\u63a5\u901a\u8fc7\u4e0a\u8bc9\u7c7b\u4f3c\u7684\u4f8b\u5b50\u53bb\u6267\u884c\uff0c\u56e0\u4e3a\u6700\u5c0f\u7684\u662f1min\u3002\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u7684\u65b9\u6cd5\u3002<\/p>\n<pre class=\"hljs undefined\"><code>* * * * * \/scripts\/script.sh\n* * * * *  sleep 30; \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u591a\u4e2a\u4efb\u52a1\u5728\u4e00\u6761\u547d\u4ee4\u4e2d\u914d\u7f6e\n<pre class=\"hljs undefined\"><code>* * * * * \/scripts\/script.sh; \/scripts\/scrit2.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5e74\u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>@yearly \/scripts\/script.sh<\/code><\/pre>\n<p>@yearly \u7c7b\u4f3c\u4e8e\u201c0 0 1 1 *\u201d\u3002\u5b83\u4f1a\u5728\u6bcf\u5e74\u7684\u7b2c\u4e00\u5206\u949f\u5185\u6267\u884c\uff0c\u901a\u5e38\u6211\u4eec\u53ef\u4ee5\u7528\u8fd9\u4e2a\u53d1\u9001\u65b0\u5e74\u7684\u95ee\u5019\u3002<\/li>\n<li>\u6bcf\u6708\u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>@yearly \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5468\u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>@yearly \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5929\u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>@yearly \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\n<pre class=\"hljs undefined\"><code>@yearly \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u7cfb\u7edf\u91cd\u542f\u65f6\u6267\u884c\n<pre class=\"hljs undefined\"><code>@reboot \/scripts\/script.sh<\/code><\/pre>\n<\/li>\n<li>\u5c06 Cron \u7ed3\u679c\u91cd\u5b9a\u5411\u7684\u7279\u5b9a\u7684\u8d26\u6237<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ccron \u53ea\u4f1a\u5c06\u7ed3\u679c\u8be6\u60c5\u53d1\u9001\u7ed9 cron \u88ab\u5236\u5b9a\u7684\u7528\u6237\u3002\u5982\u679c\u9700\u8981\u53d1\u9001\u7ed9\u5176\u4ed6\u7528\u6237\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u7684\u65b9\u5f0f\uff1a<\/p>\n<pre class=\"hljs undefined\"><code># crontab -l\nMAIL=bob\n0 2 * * * \/script\/backup.sh<\/code><\/pre>\n<\/li>\n<li>\u5c06\u6240\u6709\u7684 cron \u547d\u4ee4\u5907\u4efd\u5230\u6587\u672c\u6587\u4ef6\u5f53\u4e2d<br \/>\n\u8fd9\u662f\u4e00\u4e2a\u5f53\u6211\u4eec\u4e22\u5931\u4e86cron\u547d\u4ee4\u540e\u65b9\u4fbf\u5feb\u901f\u7684\u4e00\u4e2a\u6062\u590d\u65b9\u5f0f\u3002<br \/>\n\u4e0b\u9762\u662f\u5229\u7528\u8fd9\u4e2a\u65b9\u5f0f\u6062\u590dcron\u7684\u4e00\u4e2a\u5c0f\u4f8b\u5b50\u3002\uff08\u770b\u770b\u5c31\u884c~\uff09<br \/>\n\u9996\u5148\uff1a\u68c0\u67e5\u5f53\u524d\u7684cron<\/p>\n<pre class=\"hljs undefined\"><code># crontab -l\nMAIL=rahul\n0 2 * * * \/script\/backup.sh<\/code><\/pre>\n<p>\u7136\u540e\uff1a\u5907\u4efdcron\u5230\u6587\u4ef6\u4e2d<\/p>\n<pre class=\"hljs undefined\"><code># crontab -l &gt; cron-backup.txt\n# cat cron-backup.txt\nMAIL=rahul\n0 2 * * * \/script\/backup.sh<\/code><\/pre>\n<p>\u63a5\u7740\uff1a\u79fb\u9664\u5f53\u524d\u7684cron<\/p>\n<pre class=\"hljs undefined\"><code># crontab -r\n# crontab -l\nno crontab for root<\/code><\/pre>\n<p>\u6062\u590d\uff1a\u4ecetext file\u4e2d\u6062\u590d<\/p>\n<pre class=\"hljs undefined\"><code># crontab cron-backup.txt\n# crontab -l\nMAIL=rahul\n0 2 * * * \/script\/backup.sh<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u539f\u6587\u94fe\u63a5<\/h3>\n<hr \/>\n<p><a href=\"http:\/\/tecadmin.net\/crontab-in-linux-with-20-examples-of-cron-schedule\/\" target=\"_blank\" rel=\"noopener\">Crontab in Linux with 20 Useful Examples to Schedule Jobs<\/a><\/p>\n<\/div>\n<p>\u4f5c\u8005\uff1aLeeLom<br \/>\n\u94fe\u63a5\uff1ahttp:\/\/www.jianshu.com\/p\/d93e2b177814<br \/>\n\u4f86\u6e90\uff1a\u7b80\u4e66<br \/>\n\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\uff0c\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb Linux crontab\u548cWindows task schedules\u975e\u5e38\u7684\u76f8\u4f3c\u3002Crontab\u53ef\u4ee5\u7528\u6765\u5728\u7cfb\u7edf\u4e2d\u5b9a\u671f\u7684\u6267\u884c\u4efb\u52a1\u3002\u6bd4\u5982\uff1a\u5199\u4e86\u4e00\u4e2a\u722c\u866b\u9700\u8981\u6bcf\u5929\u65e9\u4e0a\u516b\u70b9\u6267\u884c\uff0c\u5c31\u53ef\u4ee5\u7528\u5230Crontab;\u5b89\u88c5\u7684Tomcat\u670d\u52a1\u5668\u9700\u8981\u6bcf\u5929\u51cc\u6668\u91cd\u542f\u4e00\u6b21\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5230Crontab\u3002\u603b\u4e4b\uff0c\u51e0\u4e4e\u6240\u6709\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7Crontab\u8fd9\u4e2a\u5de5\u5177\u6765\u5b8c\u6210\u3002 \u5b89\u88c5 yum install cronie` Crontab\u5728Linux\u4e0a\u7684\u7ed3\u6784 crontab\u7ed3\u6784.png \u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u4e3a\uff1a [\u5206\u949f] [\u5c0f\u65f6] [\u6bcf\u6708\u7684\u67d0\u4e00\u5929] [\u6bcf\u5e74\u7684\u67d0\u4e00\u6708] [\u6bcf\u5468\u7684\u67d0\u4e00\u5929] [\u6267\u884c\u7684\u547d\u4ee4] \u6ce8\u610f\uff1a\u8bf7\u7559\u610f\u6bcf\u4e2a\u9009\u9879\u7684\u53d6\u503c\u8303\u56f4\u3002 \u5982\u4f55 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}