<?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 Question/Suggestion. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416383#M203400</link>
    <description>Clay &amp;amp; Sri:&lt;BR /&gt;&lt;BR /&gt;Great Answers.&lt;BR /&gt;&lt;BR /&gt;Just wanted to know if my answers would work or anything wrong with that?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Brian</description>
    <pubDate>Fri, 05 Nov 2004 19:15:49 GMT</pubDate>
    <dc:creator>brian_31</dc:creator>
    <dc:date>2004-11-05T19:15:49Z</dc:date>
    <item>
      <title>Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416377#M203394</link>
      <description>Team:&lt;BR /&gt;&lt;BR /&gt;I had a question and as well as an answer to the cron scheduling below. Please tell me if i am correct.&lt;BR /&gt;&lt;BR /&gt;1. How I can run after each 14 Days. &lt;BR /&gt;2. How I can make sure that the job is running on the first working day of the month. &lt;BR /&gt;Taking only Sat-Sun into account for Holidays. &lt;BR /&gt;&lt;BR /&gt;Answer...&lt;BR /&gt;&lt;BR /&gt;For both requirements, some logic has to be built into the program that is to be run thro' cron. The cron tab entry may be set as: &lt;BR /&gt;1. &amp;lt;&amp;gt; &lt;BR /&gt;2. 0 0 1-7 * * &amp;lt;&lt;COMMAND&gt;&amp;gt; &lt;BR /&gt;&lt;BR /&gt;The &amp;lt;&lt;COMMAND&gt;&amp;gt; logic should inturn check the day. &lt;BR /&gt;&lt;BR /&gt;Is this correct? Please let me know?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/COMMAND&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Fri, 05 Nov 2004 18:12:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416377#M203394</guid>
      <dc:creator>brian_31</dc:creator>
      <dc:date>2004-11-05T18:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416378#M203395</link>
      <description>Hi Brian,&lt;BR /&gt;&lt;BR /&gt;Yes. For both you will need to build logic into your script itself. &lt;BR /&gt;&lt;BR /&gt;1. Have a script schedule it again after 14 days using 'at' command. "at" command  allows you to specify offset in 'weeks'.&lt;BR /&gt;&lt;BR /&gt;2. You can scedule your job to run for the first three days only looking for the following conditions.&lt;BR /&gt;&lt;BR /&gt;Date    Don't run        Run if  &lt;BR /&gt;----    ---------        -------  &lt;BR /&gt;1       Sat,Sun       Mon - Fri&lt;BR /&gt;2       Tue - Sun        Mon&lt;BR /&gt;3       Tue - Sun        Mon&lt;BR /&gt;&lt;BR /&gt;You have to run it on 3rd also because 2nd could be a sunday.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Fri, 05 Nov 2004 18:40:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416378#M203395</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T18:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416379#M203396</link>
      <description>As you have already surmised, cron on its own ain't that smart. We're gonna have to help him some inside your script. The key to what you are trying to do lies in a script that will convert calendar dates (or today's date if no date is supplied) into Julian Days (days which count sequentially from 4713BCE).&lt;BR /&gt;&lt;BR /&gt;For 1)&lt;BR /&gt;Make a crontab entry that looks like this:&lt;BR /&gt;15 18 * * 1 /usr/local/bin/myscript.sh&lt;BR /&gt;&lt;BR /&gt;to run at 18:15 every Monday, for example. That runs every 7 days so now your script needs some logic to run every other week.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;PATH=${PATH}:/usr/local/bin&lt;BR /&gt;export PATH&lt;BR /&gt;&lt;BR /&gt;typeset -i WEEKNO=$(( ($(cajld.sh) + 1) / 7))&lt;BR /&gt;typeset -i WK_0_or_1=$((${WEEKNO} % 2))&lt;BR /&gt;if [[ ${WK_O_or_1} -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;  echo "Do your thing"&lt;BR /&gt;else&lt;BR /&gt;  exit 0 # don't do nothing&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The ($(caljd.sh) + 1) makes each week start on a Sunday.&lt;BR /&gt;&lt;BR /&gt;Now the next one is a little more tricky but we can even expand on your baby-food definition of a workday to exclude real honest-to_God holidays as well as weekends.&lt;BR /&gt;&lt;BR /&gt;Create/update your /etc/acct/holidays file to reflect reality. (You should already have a default and very old version on your box). Caljd.sh actually looks for /etc/acct/holidays_2004 BEFORE it looks for the default /etc/acct/holidays so that this stuff even will work across year boundaries and observe holidays. You should really create a soft-link between holidays_YYYY and holidays for the current year.&lt;BR /&gt;&lt;BR /&gt;Now create a cron entry to run every Monday through Friday; this is overkill but I have no idea how many holidays you have and this won't hurt.&lt;BR /&gt;&lt;BR /&gt;15 9 * * 1-5 /usr/local/bin/myscript2.sh&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;PATH=${PATH}:/usr/local/bin&lt;BR /&gt;export PATH&lt;BR /&gt;&lt;BR /&gt;typeset -i TODAYS_MONTH=$(caljd.sh -M)&lt;BR /&gt;typeset -i PREV_MONTH_MAYBE=$(caljd.sh -p 1 -x 0 -x 6 -h -M)&lt;BR /&gt;if [[ ${TODAYS_MONTH} -ne ${PREV_MONTH_MAYBE} ]]&lt;BR /&gt;then&lt;BR /&gt;  echo "First working day of the month; do your thing"&lt;BR /&gt;else&lt;BR /&gt;  exit 0&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The -p 1 says previos day; -x 0 skip Sundays; -x 6 ditto Saturdays; -h skip holidays (as defined in /etc/acct/holidays_YYYY). -M output just the month. Basically if today's month ain't equal to yesterday's month (skipping in the same direction weekends and holidays) then it's the first working day of the month.&lt;BR /&gt;&lt;BR /&gt;I'm assuming you install the attached caljd.sh, in /usr/local/bin. Invoke as caljd.sh -u for full usage and examples.&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Nov 2004 18:45:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416379#M203396</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-11-05T18:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416380#M203397</link>
      <description>Well.. the the format of the table got messed up. Let me try this way.&lt;BR /&gt;&lt;BR /&gt;1. If the date ( date +%d) is 1, then run only if the day (date +%a) is neither Saturdy nor Sunday.&lt;BR /&gt;2. If the date is 2, then run it only if it is monday.&lt;BR /&gt;3. If the date is 3, then run it only if it is monday.&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Nov 2004 18:47:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416380#M203397</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T18:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416381#M203398</link>
      <description>By the way, I would avoid at based solutions that create new atjobs each time your script is run because if for some reason your script does not run, the next at entry is not created so the chain is broken. It's much more robust to use a cron entry.</description>
      <pubDate>Fri, 05 Nov 2004 18:49:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416381#M203398</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-11-05T18:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416382#M203399</link>
      <description>For your case 2, there is one more possibility that we need to exclude; today might be in the holidays file so we want to exist immediately. Let's modify the 2nd script to handle that case as well.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;PATH=${PATH}:/usr/local/bin&lt;BR /&gt;export PATH&lt;BR /&gt;&lt;BR /&gt;typeset -i TODAY=$(caljd.sh)&lt;BR /&gt;itypeset -i TODAY_HOLIDAY_MAYBE=$(caljd.sh -h) # skip is positive if neither -p days or -n days is specified&lt;BR /&gt;&lt;BR /&gt;if [[ ${TODAY} -ne ${TODAY_HOLIDAY_MAYBE} ]]&lt;BR /&gt;then&lt;BR /&gt;  exit 0 # today's a holiday&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;typeset -i TODAYS_MONTH=$(caljd.sh -M)&lt;BR /&gt;typeset -i PREV_MONTH_MAYBE=$(caljd.sh -p 1 -x 0 -x 6 -h -M)&lt;BR /&gt;if [[ ${TODAYS_MONTH} -ne ${PREV_MONTH_MAYBE} ]]&lt;BR /&gt;then&lt;BR /&gt;echo "First working day of the month; do your thing"&lt;BR /&gt;else&lt;BR /&gt;exit 0&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Nov 2004 19:03:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416382#M203399</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-11-05T19:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416383#M203400</link>
      <description>Clay &amp;amp; Sri:&lt;BR /&gt;&lt;BR /&gt;Great Answers.&lt;BR /&gt;&lt;BR /&gt;Just wanted to know if my answers would work or anything wrong with that?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Brian</description>
      <pubDate>Fri, 05 Nov 2004 19:15:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416383#M203400</guid>
      <dc:creator>brian_31</dc:creator>
      <dc:date>2004-11-05T19:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416384#M203401</link>
      <description>Brian,&lt;BR /&gt;&lt;BR /&gt;I imagine you would keep some kind of error checking in your script for failures? Because you are going to add some logic anyway, it doesn't take long adding couple of lines that will either page you or send you a mail so you can fix things easily in which case 'at' doesn't hurt you. Even you can add a 'trap' inside that can automatically 'at' the job in case of any failures. You can also put some logic with week numbers given by 'date' for case 2. But you already got a cooked script/program so it's just a food for thought.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Fri, 05 Nov 2004 19:22:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416384#M203401</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T19:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416385#M203402</link>
      <description>Hi Sri:&lt;BR /&gt;&lt;BR /&gt;Thanks. i have never used at. If i have to use "at" then could you give me the commands for my question?&lt;BR /&gt;&lt;BR /&gt;Thanks Again,&lt;BR /&gt;&lt;BR /&gt;Brian</description>
      <pubDate>Fri, 05 Nov 2004 19:27:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416385#M203402</guid>
      <dc:creator>brian_31</dc:creator>
      <dc:date>2004-11-05T19:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416386#M203403</link>
      <description>Hi (Again),&lt;BR /&gt;&lt;BR /&gt;I kept clicking submit and finally I could post the last message. Regarding your answers -&lt;BR /&gt;&lt;BR /&gt;1. I don't think "" is a valid cron entry. ;-).&lt;BR /&gt;2. Taking only Sat-Sun as holidays, you don't need to run the script everyday from 1st to 7th.&lt;BR /&gt;&lt;BR /&gt;I believe you already got a working solution in hand so you don't have to work hard unless you want to devise one yourself.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Fri, 05 Nov 2004 19:29:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416386#M203403</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T19:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416387#M203404</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;'man at' gives you what you need. To schedule a job after 14 days or 2 weeks run&lt;BR /&gt;&lt;BR /&gt;at now + 2 weeks &amp;lt; your_job&lt;BR /&gt;&lt;BR /&gt;To list your at jobs&lt;BR /&gt;&lt;BR /&gt;at -l&lt;BR /&gt;&lt;BR /&gt;An example to use 'trap' in case of any failures.&lt;BR /&gt;&lt;BR /&gt;schedule()&lt;BR /&gt;{&lt;BR /&gt;at now + 2 weeks &amp;lt; your_job &amp;gt; /tmp/log$$ 2&amp;gt;&amp;amp;1&lt;BR /&gt;mailx -s "at status" your_id@yourmail.com &amp;lt; /tmp/log$$&lt;BR /&gt;rm -f /tmp/log$$&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;trap schedule 0 1 2 3 4&lt;BR /&gt;&lt;BR /&gt;Put the above before the contents of your script&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Fri, 05 Nov 2004 19:39:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416387#M203404</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T19:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416388#M203405</link>
      <description>OK.. You gave me more than enough points already. So, please award '0' for this one and the last one and any unassigned so far... Thanks.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Fri, 05 Nov 2004 19:40:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416388#M203405</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-11-05T19:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cron Question/Suggestion.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416389#M203406</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Try this link&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237796" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237796&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Singaram</description>
      <pubDate>Thu, 11 Nov 2004 16:48:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/cron-question-suggestion/m-p/3416389#M203406</guid>
      <dc:creator>Singaram</dc:creator>
      <dc:date>2004-11-11T16:48:57Z</dc:date>
    </item>
  </channel>
</rss>

