<?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: Cron help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222770#M467147</link>
    <description>Why not run it every Friday and have the script decide if it should run your job or not.  You can accomplish this with a simple if statement.  So on 2/5 when the job runs you touch a file.  on 2/12 when the job runs it looks for the file.  If it finds the file it removes the file and exits.  Tne on 2/19 since the file does not exist it will run the job and touch the file.</description>
    <pubDate>Mon, 01 Feb 2010 16:30:11 GMT</pubDate>
    <dc:creator>Larry Klasmier</dc:creator>
    <dc:date>2010-02-01T16:30:11Z</dc:date>
    <item>
      <title>Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222769#M467146</link>
      <description>I have script that needs to run every other Friday?  Anyone have running this in cron.&lt;BR /&gt;&lt;BR /&gt;The script needs to run 2/5/10 and next run should be 2/19/10&lt;BR /&gt;&lt;BR /&gt;Thanks for any help.</description>
      <pubDate>Mon, 01 Feb 2010 16:10:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222769#M467146</guid>
      <dc:creator>balaji_vvv</dc:creator>
      <dc:date>2010-02-01T16:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222770#M467147</link>
      <description>Why not run it every Friday and have the script decide if it should run your job or not.  You can accomplish this with a simple if statement.  So on 2/5 when the job runs you touch a file.  on 2/12 when the job runs it looks for the file.  If it finds the file it removes the file and exits.  Tne on 2/19 since the file does not exist it will run the job and touch the file.</description>
      <pubDate>Mon, 01 Feb 2010 16:30:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222770#M467147</guid>
      <dc:creator>Larry Klasmier</dc:creator>
      <dc:date>2010-02-01T16:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222771#M467148</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;You want to use the modulus operator and check the remainder when divided by 2.  There are only two results, 0 or 1.  The SUMS stored are integers increasing by one every week.  So the operation is 1/2, 2/2, 3/2, 4/2, 5/2, etc.&lt;BR /&gt;&lt;BR /&gt;This becomes a boolean flag for you to trap on.  Only trick is to save the last SUM in an file, which becomes an important part of the algorithm.&lt;BR /&gt;&lt;BR /&gt;Here is Midnight every other Friday&lt;BR /&gt;&lt;BR /&gt;weekday&lt;BR /&gt;The day of the week, 0-6, 0=Sunday&lt;BR /&gt;&lt;BR /&gt;minute  hour  monthday  month  weekday FLAG command&lt;BR /&gt;&lt;BR /&gt;00 00 * * 5 /dir/script&lt;BR /&gt;&lt;BR /&gt;####################&lt;BR /&gt;script&lt;BR /&gt;#####################&lt;BR /&gt;&lt;BR /&gt;/home/your_dir/FLAG filename.&lt;BR /&gt;FLAG=$((cat FLAG_FILE))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;mymodulus=$(( $FLAG % 2 ))&lt;BR /&gt;1=1%2&lt;BR /&gt;&lt;BR /&gt;case $FLAG in&lt;BR /&gt;  "0") Execute script;;&lt;BR /&gt;  "1") ;;&lt;BR /&gt;&lt;BR /&gt;FLAG=$(($FLAG+1))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;2&lt;BR /&gt;echo $FLAG&amp;gt;FLAG_FILE&lt;BR /&gt;##################################&lt;BR /&gt;Next time&lt;BR /&gt;##################################&lt;BR /&gt;&lt;BR /&gt;/home/your_dir/FLAG filename.&lt;BR /&gt;FLAG=$((cat FLAG_FILE))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;mymodulus=$(( $FLAG % 2 ))&lt;BR /&gt;0=2%2&lt;BR /&gt;&lt;BR /&gt;case $FLAG in&lt;BR /&gt;  "0") Execute script;;&lt;BR /&gt;  "1") ;;&lt;BR /&gt;&lt;BR /&gt;FLAG=$(($FLAG+1))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;3&lt;BR /&gt;echo $FLAG&amp;gt;FLAG_FILE&lt;BR /&gt;##################################&lt;BR /&gt;Next time&lt;BR /&gt;##################################&lt;BR /&gt;&lt;BR /&gt;/home/your_dir/FLAG filename.&lt;BR /&gt;FLAG=$((cat FLAG_FILE))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;3&lt;BR /&gt;&lt;BR /&gt;mymodulus=$(( $FLAG % 2 ))&lt;BR /&gt;1=3%2&lt;BR /&gt;&lt;BR /&gt;case $FLAG in&lt;BR /&gt;  "0") Execute script;;&lt;BR /&gt;  "1") ;;&lt;BR /&gt;&lt;BR /&gt;FLAG=$(($FLAG+1))&lt;BR /&gt;echo $FLAG&lt;BR /&gt;4&lt;BR /&gt;echo $FLAG&amp;gt;FLAG_FILE&lt;BR /&gt;&lt;BR /&gt;Etc.</description>
      <pubDate>Mon, 01 Feb 2010 17:07:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222771#M467148</guid>
      <dc:creator>Michael Steele_2</dc:creator>
      <dc:date>2010-02-01T17:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222772#M467149</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] If it finds the file it removes the&lt;BR /&gt;&amp;gt; file and exits. [...]&lt;BR /&gt;&lt;BR /&gt;Of course, if someone deletes the file, then&lt;BR /&gt;you can get the wrong result with no way to&lt;BR /&gt;detect the problem.  You can also do things&lt;BR /&gt;like store a number (say, 0 or 1) in a file,&lt;BR /&gt;and look at that value instead of simply&lt;BR /&gt;testing the existence of the file.&lt;BR /&gt;&lt;BR /&gt;bash$ echo 0 &amp;gt; flag_file&lt;BR /&gt;&lt;BR /&gt;bash$ var=` cat flag_file `&lt;BR /&gt;bash$ var=` expr 1 - $var `&lt;BR /&gt;bash$ echo $var&lt;BR /&gt;1&lt;BR /&gt;bash$ echo $var &amp;gt; flag_file&lt;BR /&gt;&lt;BR /&gt;bash$ var=` cat flag_file `&lt;BR /&gt;bash$ var=` expr 1 - $var `&lt;BR /&gt;bash$ echo $var&lt;BR /&gt;0&lt;BR /&gt;bash$ echo $var &amp;gt; flag_file&lt;BR /&gt;&lt;BR /&gt;bash$ var=` cat flag_file `&lt;BR /&gt;bash$ var=` expr 1 - $var `&lt;BR /&gt;bash$ echo $var&lt;BR /&gt;1&lt;BR /&gt;bash$ echo $var &amp;gt; flag_file&lt;BR /&gt;[...]&lt;BR /&gt;&lt;BR /&gt;Modern shells can do the math without using&lt;BR /&gt;"expr", and I didn't show a test for valid&lt;BR /&gt;file contents, but, as usual, many things are&lt;BR /&gt;possible.</description>
      <pubDate>Mon, 01 Feb 2010 18:57:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222772#M467149</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-02-01T18:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222773#M467150</link>
      <description>You can put a few lines in your script, which can modify file /var/spool/cron/crontabs according to what you need every week. Got to do it carefully, but it wont be that messy.</description>
      <pubDate>Mon, 01 Feb 2010 19:28:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222773#M467150</guid>
      <dc:creator>Tingli</dc:creator>
      <dc:date>2010-02-01T19:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222774#M467151</link>
      <description>Thanks for your ideas.  I thought i can directly cron doing the job without any script help.&lt;BR /&gt;&lt;BR /&gt;will this work?&lt;BR /&gt;00 08 1-7,15-21 * 3 /home/oracle/test.sh</description>
      <pubDate>Mon, 01 Feb 2010 20:17:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222774#M467151</guid>
      <dc:creator>balaji_vvv</dc:creator>
      <dc:date>2010-02-01T20:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222775#M467152</link>
      <description>&lt;!--!*#--&gt;&amp;gt; will this work?&lt;BR /&gt;&lt;BR /&gt;Do all months have exactly 28 days?</description>
      <pubDate>Mon, 01 Feb 2010 20:33:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222775#M467152</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-02-01T20:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222776#M467153</link>
      <description>&lt;!--!*#--&gt;I suppose you could have your script run every Friday and then take the julian day of the year and use that to alternate.  Of course do you care that it may do it twice when a new year starts?&lt;BR /&gt;if (( $(date +%j) / 7 % 2 == 0)); then&lt;BR /&gt;   echo Even&lt;BR /&gt;else&lt;BR /&gt;   echo Odd&lt;BR /&gt;fi</description>
      <pubDate>Tue, 02 Feb 2010 11:50:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222776#M467153</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-02-02T11:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222777#M467154</link>
      <description>Hi balaji,&lt;BR /&gt;&lt;BR /&gt;if you can't handle this in ONE cron job, you can definetly do that by using more than one cron jobs-entries.&lt;BR /&gt;&lt;BR /&gt;is'nt it simple :)&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Feb 2010 12:12:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222777#M467154</guid>
      <dc:creator>Muhammad Ahmad</dc:creator>
      <dc:date>2010-02-02T12:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222778#M467155</link>
      <description>&amp;gt;Muhammad: if you can't handle this in ONE cron job, you can definitely do that by using more than one cron jobs-entries.&lt;BR /&gt;&lt;BR /&gt;Oh I see.  You fill it up with 25/26 entries and change it each year.  :-)</description>
      <pubDate>Tue, 02 Feb 2010 13:10:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222778#M467155</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-02-02T13:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222779#M467156</link>
      <description>&amp;gt;&amp;gt;will this work?&lt;BR /&gt;&amp;gt;&amp;gt;00 08 1-7,15-21 * 3 /home/oracle/test.sh&lt;BR /&gt;&lt;BR /&gt;No, I don't think this will do what you want.  This job will run on the 1-7, the 15-21 AND on Friday.  The job will run IF ANY of the last 3 fields are true.&lt;BR /&gt;&lt;BR /&gt;Note the example from the cron man page:&lt;BR /&gt;&lt;BR /&gt;&lt;QUOTE&gt;&lt;BR /&gt;Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are cumulative.  For example,&lt;BR /&gt;&lt;BR /&gt;0 0 1,15 * 1   command&lt;BR /&gt;&lt;BR /&gt;runs command at midnight on the first and fifteenth of each month, as well as every Monday. &lt;BR /&gt;&lt;/QUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;Do all months have exactly 28 days?&lt;BR /&gt;Well, yes they do! ;)</description>
      <pubDate>Tue, 02 Feb 2010 14:38:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222779#M467156</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2010-02-02T14:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222780#M467157</link>
      <description>&lt;!--!*#--&gt;&amp;gt; &amp;gt;&amp;gt;Do all months have exactly 28 days?&lt;BR /&gt;&amp;gt; Well, yes they do! ;)&lt;BR /&gt;&lt;BR /&gt;This must be some new meaning for the word&lt;BR /&gt;"exactly" (which I used for a reason).</description>
      <pubDate>Tue, 02 Feb 2010 14:45:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222780#M467157</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-02-02T14:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222781#M467158</link>
      <description>I finally ended up using Larry Klasmier  idea.&lt;BR /&gt;&lt;BR /&gt;Thanks for everyone contributed.&lt;BR /&gt;Here is the logic, if anyone needs it.&lt;BR /&gt;This will run biweekly sunday at 10.00am.&lt;BR /&gt;&lt;BR /&gt;My cron &lt;BR /&gt;--------&lt;BR /&gt;00 10 * * 6 /myscript&lt;BR /&gt;&lt;BR /&gt;My script&lt;BR /&gt;---------&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/bash&lt;BR /&gt;&lt;BR /&gt;if [ -e /tmp/fchek ] ; then&lt;BR /&gt;     rm -f /tmp/fchek&lt;BR /&gt;else&lt;BR /&gt;     touch /tmp/fchek&lt;BR /&gt;     exit 0&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;sh /myscript&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Explanation :  (Not for experts!)&lt;BR /&gt;-------------&lt;BR /&gt;Script will look for a file /tmp/fcheck on the first run, it wont find it and it will create  and exit. On the next week it will find the file, remove it and execute my script. On third week it wont find my file, create it and exit and so on....</description>
      <pubDate>Wed, 03 Feb 2010 15:45:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222781#M467158</guid>
      <dc:creator>balaji_vvv</dc:creator>
      <dc:date>2010-02-03T15:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222782#M467159</link>
      <description>Resolved. See above</description>
      <pubDate>Wed, 03 Feb 2010 15:46:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222782#M467159</guid>
      <dc:creator>balaji_vvv</dc:creator>
      <dc:date>2010-02-03T15:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222783#M467160</link>
      <description>&lt;!--!*#--&gt;&amp;gt; rm -f /tmp/fchek&lt;BR /&gt;&amp;gt; else&lt;BR /&gt;&lt;BR /&gt;If someone changes the permissions on this&lt;BR /&gt;file, then the "rm" could fail (silently).&lt;BR /&gt;&lt;BR /&gt;Of course, this should never happen.  How&lt;BR /&gt;important is it that this job run exactly&lt;BR /&gt;every two weeks?  Sometimes the easy way is&lt;BR /&gt;good enough.  Sometimes it's not.  You get to&lt;BR /&gt;decide what's good enough.</description>
      <pubDate>Wed, 03 Feb 2010 16:11:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222783#M467160</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-02-03T16:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cron help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222784#M467161</link>
      <description>I will keep this file in secure location.  It's not very critical if it fail to run, as everyone in that group will get email, and they will take care of it.</description>
      <pubDate>Wed, 03 Feb 2010 16:18:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-help/m-p/5222784#M467161</guid>
      <dc:creator>balaji_vvv</dc:creator>
      <dc:date>2010-02-03T16:18:28Z</dc:date>
    </item>
  </channel>
</rss>

