<?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: scheduling a cron job on the last day of the month in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099822#M807409</link>
    <description>Singaram -&lt;BR /&gt;As per Pete's suggestion:&lt;BR /&gt;TZ=PST8PDT-24 date +%d | read DOM&lt;BR /&gt;if [ "$DOM" -eq 1 ]&lt;BR /&gt;then&lt;BR /&gt;do your thing&lt;BR /&gt;fi&lt;BR /&gt;TZ=PST8PDT-24 date +%d | read DOM==&amp;gt; says DOM is equal to the day of the month following today.&lt;BR /&gt;&lt;BR /&gt;Best of luck.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;dl&lt;BR /&gt;</description>
    <pubDate>Wed, 22 Oct 2003 14:36:03 GMT</pubDate>
    <dc:creator>Dave La Mar</dc:creator>
    <dc:date>2003-10-22T14:36:03Z</dc:date>
    <item>
      <title>scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099819#M807406</link>
      <description>Is there any way to schedule a job on the last day of every calendar month. Ex on Jan 31st or feb 28th or march 31st or April 30 the etc. &lt;BR /&gt;&lt;BR /&gt;I did solve in round about way.Like to know the best way.&lt;BR /&gt;&lt;BR /&gt;Singaram</description>
      <pubDate>Wed, 22 Oct 2003 11:33:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099819#M807406</guid>
      <dc:creator>Singaram</dc:creator>
      <dc:date>2003-10-22T11:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099820#M807407</link>
      <description>There's no direct way to do this via cron.  You'll have to set up a cron job that invokes a script that figures out the last day of the month.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Oct 2003 11:39:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099820#M807407</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2003-10-22T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099821#M807408</link>
      <description>One method is to literally run the script everyday and let it decide if this is the last day of the month w/o doing the 30 days hath September ...&lt;BR /&gt;&lt;BR /&gt;Note: Cron has a very limited PATH so make sure that whereever you install the attached caljd.sh, the first thing that your cron script does is sets and exports PATH&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;export PATH=/usr/bin:/usr/local/bin&lt;BR /&gt;if [[ $(caljd.sh -M) -ne $(caljd.sh -n 1 -M) ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Last day of month; your commands go here"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;This compares the current date's month with the next days (-n 1). If they differ then it's the last day of the month.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Oct 2003 11:42:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099821#M807408</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-10-22T11:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099822#M807409</link>
      <description>Singaram -&lt;BR /&gt;As per Pete's suggestion:&lt;BR /&gt;TZ=PST8PDT-24 date +%d | read DOM&lt;BR /&gt;if [ "$DOM" -eq 1 ]&lt;BR /&gt;then&lt;BR /&gt;do your thing&lt;BR /&gt;fi&lt;BR /&gt;TZ=PST8PDT-24 date +%d | read DOM==&amp;gt; says DOM is equal to the day of the month following today.&lt;BR /&gt;&lt;BR /&gt;Best of luck.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;dl&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Oct 2003 14:36:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099822#M807409</guid>
      <dc:creator>Dave La Mar</dc:creator>
      <dc:date>2003-10-22T14:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099823#M807410</link>
      <description>Hi,&lt;BR /&gt;I hereby quote Craig Rants from Favourite Sysadmin Scripts:&lt;BR /&gt; &lt;BR /&gt;There is not much to it, but it always solves the problem of running a script on the last day of the month. Put 28-31 (for days) in your crontab and put this little section in for date determination.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;if test `TZ=MET-24 date +%d` = 01&lt;BR /&gt;then&lt;BR /&gt;exec command&lt;BR /&gt;else&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;unqoute.&lt;BR /&gt; &lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Wed, 22 Oct 2003 14:55:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099823#M807410</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-10-22T14:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099824#M807411</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I always like playing with hacks like this&lt;BR /&gt;that use the 'cal' command to get the answer.&lt;BR /&gt;&lt;BR /&gt;Something like this could work:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;# lastday.sh&lt;BR /&gt;&lt;BR /&gt;TODAY=$(date +\%d)&lt;BR /&gt;LASTDAY=$(cal | tail -2 | head -1 | awk '{print $NF}')&lt;BR /&gt;&lt;BR /&gt;if [[ $TODAY = $LASTDAY ]];&lt;BR /&gt;then&lt;BR /&gt;        echo "Last day of the month."&lt;BR /&gt;else&lt;BR /&gt;        echo "Not the last day of the month."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Oct 2003 16:23:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099824#M807411</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2003-10-22T16:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099825#M807412</link>
      <description>Thanks JP. &lt;BR /&gt;I like yours as it is very simple. &lt;BR /&gt;But still i dont like the idea of running the script every day. Having found the last day cant we add the cron job for the last day thru a script.&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;BR /&gt;Singaram</description>
      <pubDate>Wed, 22 Oct 2003 16:38:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099825#M807412</guid>
      <dc:creator>Singaram</dc:creator>
      <dc:date>2003-10-22T16:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099826#M807413</link>
      <description>Singaram,&lt;BR /&gt;&lt;BR /&gt;Like John Korteman suggested, you do not have to run it every month day, only the last couple, starting the 28th:&lt;BR /&gt;&lt;BR /&gt;&lt;MIN&gt; &lt;HOUR&gt; 28-31 &lt;MONTH&gt; &lt;WKDAY&gt; &lt;YOUR script=""&gt;&lt;/YOUR&gt;&lt;BR /&gt;so it runs maximum 4 days per month, for a short while..&lt;BR /&gt;&lt;BR /&gt;p.s. would be nive, if you gave points to the solutions you appreciate..&lt;/WKDAY&gt;&lt;/MONTH&gt;&lt;/HOUR&gt;&lt;/MIN&gt;</description>
      <pubDate>Thu, 23 Oct 2003 02:49:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099826#M807413</guid>
      <dc:creator>Kasper Haitsma</dc:creator>
      <dc:date>2003-10-23T02:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099827#M807414</link>
      <description>Hi Singaram,&lt;BR /&gt; &lt;BR /&gt;you don't need to run it every day, it will do if you run it at the 28th till 31th of every month.&lt;BR /&gt; &lt;BR /&gt;Volkmar</description>
      <pubDate>Thu, 23 Oct 2003 02:55:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099827#M807414</guid>
      <dc:creator>V. Nyga</dc:creator>
      <dc:date>2003-10-23T02:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099828#M807415</link>
      <description>volkumar &lt;BR /&gt;&lt;BR /&gt;I want to run a cron job only on the first of the month, which finds out the last day of the month and should automatically schedule the month end job on the last day.&lt;BR /&gt;&lt;BR /&gt;Now my question is "Is there a way to schedule a cron job automatically from a script?"&lt;BR /&gt;&lt;BR /&gt;Thanks to all&lt;BR /&gt;&lt;BR /&gt;Kasper haitsma&lt;BR /&gt;&lt;BR /&gt;I will assign points as soon as i conclude this discussion. &lt;BR /&gt;&lt;BR /&gt;Singaram</description>
      <pubDate>Thu, 23 Oct 2003 08:01:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099828#M807415</guid>
      <dc:creator>Singaram</dc:creator>
      <dc:date>2003-10-23T08:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099829#M807416</link>
      <description>Hi Singaram,&lt;BR /&gt;&lt;BR /&gt;I'm not good in shell scripting, it should be possible, but you have to rewrite your crontab file '/var/spool/cron/crontabs/root' every month:&lt;BR /&gt;At the first day you have to check (with cron) which month you have. Then set the last day (for January, March, May ... 31th for example), then read you crontab file, delete (for example) the last line and add a new one with the current 'last day'.&lt;BR /&gt;Then write the new crontab file.&lt;BR /&gt; &lt;BR /&gt;Good luck&lt;BR /&gt;Volkmar</description>
      <pubDate>Thu, 23 Oct 2003 08:26:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099829#M807416</guid>
      <dc:creator>V. Nyga</dc:creator>
      <dc:date>2003-10-23T08:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099830#M807417</link>
      <description>you could also add 12 cron lines, one for each month..</description>
      <pubDate>Thu, 23 Oct 2003 08:28:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099830#M807417</guid>
      <dc:creator>Kasper Haitsma</dc:creator>
      <dc:date>2003-10-23T08:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099831#M807418</link>
      <description>In that case, try looking at 'at'. With that you can do what you want: schedule a script from a script.&lt;BR /&gt;Or use crontab -l | &lt;COMMANDS to="" change="" script="" line=""&gt; | crontab&lt;BR /&gt;&lt;BR /&gt;The commands to change the script line would become something like this:&lt;BR /&gt;&lt;BR /&gt;awk '/&amp;lt;scriptname&amp;gt;/ { $5='$LASTDAY'}&lt;BR /&gt;{print}'&lt;BR /&gt;&lt;BR /&gt;As long as LASTDAY contains the last day of the month like in JP's script, it work.&lt;BR /&gt;Of course there are cleaner ways to do it, but is should work.&lt;/COMMANDS&gt;</description>
      <pubDate>Thu, 23 Oct 2003 08:28:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099831#M807418</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2003-10-23T08:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099832#M807419</link>
      <description>Singaram,&lt;BR /&gt;&lt;BR /&gt;To do it your way, run the cron job on the first of the month to calculate the end of the month day (let's call it $EOM, "Oct 31, for example).  Then invoke an at job to run your end of month job thusly:&lt;BR /&gt;&lt;BR /&gt;at -f /full/path/of/your/job $EOM &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Oct 2003 08:35:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099832#M807419</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2003-10-23T08:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099833#M807420</link>
      <description>JP&lt;BR /&gt;&lt;BR /&gt;I have to find the last day of the month avoiding saturday and sunday. &lt;BR /&gt;&lt;BR /&gt;Any short cuts on awk?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Sing&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Oct 2003 14:16:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099833#M807420</guid>
      <dc:creator>Singaram</dc:creator>
      <dc:date>2003-10-23T14:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099834#M807421</link>
      <description>You are still doing this the hard way. THe overhead of running a cronjon once per day is trivial. Setup your cron to run Mondays thru Friday (1-5) and then make one small change to my first solution.&lt;BR /&gt;&lt;BR /&gt;if [[ $(caljd.sh -M) -ne $(caljd.sh -n 1 -x 6 -x 0 -M) ]]&lt;BR /&gt;then&lt;BR /&gt;  echo "Do your thing"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;That says compare today's month with tomorrow's month (-n 1) unless that day falls on a Saturday -x 6 or a Sunday -x 0. This has the effect of running either on the last day of the month or on the last Friday.&lt;BR /&gt;Want to get more complicated? Add -h and it will skip holidays as well if your /etc/acct/holidays is setup. Invoke as caljd.sh -u for full usage.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Oct 2003 14:29:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099834#M807421</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-10-23T14:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: scheduling a cron job on the last day of the month</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099835#M807422</link>
      <description>Hi Sing,&lt;BR /&gt;&lt;BR /&gt;My little hack with 'cal' will find the last day of the month, but if you need it to be a weekday the hack gets very tricky.&lt;BR /&gt;&lt;BR /&gt;Probably the easiest thing for you to do is to use Clay's script.  His script handles all kinds of date calculations and is very handy to have in your kit.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Oct 2003 14:57:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scheduling-a-cron-job-on-the-last-day-of-the-month/m-p/3099835#M807422</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2003-10-23T14:57:55Z</dc:date>
    </item>
  </channel>
</rss>

