{"id":519,"date":"2011-01-28T00:30:38","date_gmt":"2011-12-11T21:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/cron-entry-to-reboot-a-server-the-first-sunday-of-every-month\/"},"modified":"2011-01-28T00:30:38","modified_gmt":"2011-12-11T21:51:50","slug":"cron-entry-to-reboot-a-server-the-first-sunday-of-every-month","status":"publish","type":"post","link":"\/blog\/index.php\/cron-entry-to-reboot-a-server-the-first-sunday-of-every-month\/","title":{"rendered":"Cron entry to reboot a server the first Sunday of every month"},"content":{"rendered":"<p>This cannot be expressed in the typical crontab syntax, so we run a script every sunday in the crontab:<br \/>\n00 11 kraftek.html POSTS rescue rescued.html rescued.txt x y z kraftek.html POSTS rescue rescued.html rescued.txt x y z 0 root \/scripts\/monthlyreboot.ksh &gt; \/var\/log\/rebootlog 2&gt;&amp;1<br \/>\nThe script checks if this is the first sunday of the current month, if it is, it performs a reboot, the contents of<br \/>\n\/scripts\/monthlyreboot.ksh are:<br \/>\n#!\/bin\/ksh<br \/>\n# get today&#8217;s month and year<br \/>\nT=`date +%m&#8221; &#8220;%Y | sed &#8216;s\/^0\/\/&#8217;`<br \/>\n# get this month&#8217;s first sunday<br \/>\nS=`cal $T | cut -c 1-2 | sed &#8216;s\/ \/\/g&#8217; | grep . | head -2 | tail -1`<br \/>\n# get what day of the month today is<br \/>\nD=`date +%d | sed &#8216;s\/^0\/\/&#8217;`<br \/>\necho -n &#8220;`date` &#8212; the day is $D, first sunday of $T is $S&#8221;<br \/>\nif [ $D -eq $S ];then<br \/>\necho &#8220;, so we are going to reboot&#8221;<br \/>\nsleep 3<br \/>\n\/sbin\/shutdown -t 00 -r now<br \/>\nelse<br \/>\necho &#8220;, no reboot today&#8221;<br \/>\nfi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This cannot be expressed in the typical crontab syntax, so we run a script every sunday in the crontab: 00 11 kraftek.html POSTS rescue rescued.html rescued.txt x y z kraftek.html POSTS rescue rescued.html rescued.txt x y z 0 root \/scripts\/monthlyreboot.ksh &gt; \/var\/log\/rebootlog 2&gt;&amp;1 The script checks if this is the first sunday of the current [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-519","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=519"}],"version-history":[{"count":0,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/519\/revisions"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}