<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: scripting cron job in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681869#M102885</link>
    <description>I don't like the idea of rebooting like this but:&lt;BR /&gt;&lt;BR /&gt;The easy way to do this is run your script each Sunday and have it decide if it is the 1st Sunday and execute or simply exit if not.&lt;BR /&gt;&lt;BR /&gt;Install the attached caljd.sh in /usr/local/bin&lt;BR /&gt;&lt;BR /&gt;Your script which is executed by cron every Sunday at whatever time you like looks like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;export PATH=${PATH}:/usr/local/bin&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;if [[ $(caljd.sh -N) -eq 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "1st Sunday; do your thing"&lt;BR /&gt;#   set the value of ${STAT}&lt;BR /&gt;  fi&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;---------------------------------------&lt;BR /&gt;&lt;BR /&gt;The last Saturday is similar wee look at the month today and 7 days hence and if they differ, today is the last Saturday:&lt;BR /&gt;&lt;BR /&gt;export PATH=${PATH}:/usr/local/bin&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;if [[ $(caljd.sh -M) -ne $(caljd.sh -M -n 7)  ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Last Saturday; do your thing"&lt;BR /&gt;#   set the value of ${STAT}&lt;BR /&gt;  fi&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;Invoke as caljd.sh -u for many examples.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 30 Nov 2005 17:51:16 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2005-11-30T17:51:16Z</dc:date>
    <item>
      <title>scripting cron job</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681868#M102884</link>
      <description>Does anyone have a snippet of code to ID the last sunday of each month or first saturday of each month?  I basically have servers that I want to reboot during those times, and need a wrapper script to launch shutdown.  Bi-weekly finding even/odd week was easy, but look for creative/effective ideas on the once per month stuff.</description>
      <pubDate>Wed, 30 Nov 2005 17:27:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681868#M102884</guid>
      <dc:creator>Dan Matlock_1</dc:creator>
      <dc:date>2005-11-30T17:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: scripting cron job</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681869#M102885</link>
      <description>I don't like the idea of rebooting like this but:&lt;BR /&gt;&lt;BR /&gt;The easy way to do this is run your script each Sunday and have it decide if it is the 1st Sunday and execute or simply exit if not.&lt;BR /&gt;&lt;BR /&gt;Install the attached caljd.sh in /usr/local/bin&lt;BR /&gt;&lt;BR /&gt;Your script which is executed by cron every Sunday at whatever time you like looks like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;export PATH=${PATH}:/usr/local/bin&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;if [[ $(caljd.sh -N) -eq 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "1st Sunday; do your thing"&lt;BR /&gt;#   set the value of ${STAT}&lt;BR /&gt;  fi&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;---------------------------------------&lt;BR /&gt;&lt;BR /&gt;The last Saturday is similar wee look at the month today and 7 days hence and if they differ, today is the last Saturday:&lt;BR /&gt;&lt;BR /&gt;export PATH=${PATH}:/usr/local/bin&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;if [[ $(caljd.sh -M) -ne $(caljd.sh -M -n 7)  ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Last Saturday; do your thing"&lt;BR /&gt;#   set the value of ${STAT}&lt;BR /&gt;  fi&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;Invoke as caljd.sh -u for many examples.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Nov 2005 17:51:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681869#M102885</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-11-30T17:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: scripting cron job</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681870#M102886</link>
      <description>To get last sunday of the month then,&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#sunday.sh&lt;BR /&gt;# /usr/bin/sunday.sh&lt;BR /&gt;&lt;BR /&gt;if [[ $(date +'%d') -eq $(cal | cut -b 1,2 | grep -v '^$' | tail -1) ]]&lt;BR /&gt;then&lt;BR /&gt;  # You can do reboot. It is not recommeded anway&lt;BR /&gt;  shutdown -r now&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# END&lt;BR /&gt;exit 0&lt;BR /&gt;############&lt;BR /&gt;&lt;BR /&gt;To execute shutdown on first saturday of the month then,&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#saturday.sh&lt;BR /&gt;# /usr/bin/saturday.sh&lt;BR /&gt;&lt;BR /&gt;if [[ $(date +'%d') -eq $(cal | cut -b 19,20 | awk '{ if ( $1 ~ "S") { getline;print; }}') ]]&lt;BR /&gt;then&lt;BR /&gt;  # You can do reboot. It is not recommeded anway&lt;BR /&gt;  shutdown -r now&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# END&lt;BR /&gt;exit 0&lt;BR /&gt;############&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Put this script in cron tab as,&lt;BR /&gt;&lt;BR /&gt;0 7 * * * /usr/bin/sunday.sh 1&amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;it will execute every day morning 7'o clock.. And do reboot on the last sunday or saturday.&lt;BR /&gt;&lt;BR /&gt;Change sunday.sh to saturday.sh to execute on first saturday.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 01 Dec 2005 02:56:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-cron-job/m-p/3681870#M102886</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-12-01T02:56:47Z</dc:date>
    </item>
  </channel>
</rss>

