{"id":187,"date":"2013-04-02T13:42:25","date_gmt":"2013-04-02T13:42:25","guid":{"rendered":"http:\/\/www.nicovs.be\/?p=187"},"modified":"2013-04-02T13:45:46","modified_gmt":"2013-04-02T13:45:46","slug":"schedule-cron-jobs-to-run-every-2-weeks","status":"publish","type":"post","link":"https:\/\/www.nicovs.be\/?p=187","title":{"rendered":"Schedule cron jobs to run every 2 weeks"},"content":{"rendered":"<p>There is no straight forward way to schedule a cron job so that a certain command gets executed biweekly, let&#8217;s say every 2 sunday nights&#8230;<\/p>\n<p>To be able to do this, you need to extend your cron command with a command that tests the day of the week.<\/p>\n<p>In my case I needed to perform a &#8216;clone MySQL database&#8217; on the 2nd and 4th sunday of each month to a sandbox\u00a0environment.<\/p>\n<p>This is how I&#8217;ve implemented this:<\/p>\n<pre class=\"lang:default decode:true\">30 2 8-14,22-28 * * test $(date +%u) -eq 1 &amp;&amp; sh \/root\/clone_to_sandbox.sh<\/pre>\n<p>You see that the cron job itselfs is scheduled to happen from:<\/p>\n<p>The 8th until 14th of each month and from the 22nd until the 28th of each month.<\/p>\n<p>When executing, I test if the day is the 1st of the week (Sunday = day 1 of the week). When this result is positive, the shell script will be executed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is no straight forward way to schedule a cron job so that a certain command gets executed biweekly, let&#8217;s say every 2 sunday nights&#8230; To be able to do this, you need to extend your cron command with a command that tests the day of the week. In my case I needed to perform [&hellip;]<\/p>\n","protected":false},"author":2,"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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[20,4,6],"tags":[43,38,40,39,41,42],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-centos","category-debian","category-ubuntu","tag-biweekly","tag-cron","tag-cron-job","tag-crontab","tag-schedule","tag-weekly"],"_links":{"self":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":4,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions\/362"}],"wp:attachment":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}