From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Brehl, Blake" Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: cron schedule fire only on last day of month Date: Wed, 12 Mar 2008 17:49:39 -0700 Message-ID: <06919C2CEC2A8D46A394A43403A52CFD7541CD@moh-exc-006.main.intgin.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1205369412 17193 80.91.229.12 (13 Mar 2008 00:50:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Mar 2008 00:50:12 +0000 (UTC) To: tru64-unix-managers@ornl.gov Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Thu Mar 13 01:50:39 2008 Return-path: Envelope-to: gotm-tru64-unix-managers@gmane.org Original-Received: from sws1.ornl.gov ([160.91.1.101]) by lo.gmane.org with smtp (Exim 4.50) id 1JZbeZ-0000ik-5G for gotm-tru64-unix-managers@gmane.org; Thu, 13 Mar 2008 01:50:39 +0100 Original-Received: (qmail 26790 invoked by uid 49509); 13 Mar 2008 00:49:52 -0000 Original-Sender: tru64-unix-managers-owner@ornl.gov Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 26780 invoked by uid 49501); 13 Mar 2008 00:49:52 -0000 Original-Received: from 160.91.4.110 by sws1 (envelope-from , uid 49491) with qmail-scanner-1.25 (clamdscan: 0.83/743. spamassassin: 3.0.2. Clear:RC:0(160.91.4.110):SA:0(-2.6/5.0):. Processed in 1.790654 secs); 13 Mar 2008 00:49:52 -0000 X-Spam-Status: No, hits=-2.6 required=5.0 Original-Received: from emroute3.ornl.gov (160.91.4.110) by sws1.ornl.gov with SMTP; 13 Mar 2008 00:49:50 -0000 Original-Received: from emroute3.ornl.gov ([127.0.0.1]) by emroute3.ornl.gov (PMDF V6.3-x14 #31501) with ESMTP id <0JXN00GNC8Z1CI@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 12 Mar 2008 20:49:50 -0400 (EDT) Original-Received: from CONVERSION-DAEMON.emroute3.ornl.gov by emroute3.ornl.gov (PMDF V6.3-x14 #31501) id <0JXN00L018Z1V1@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 12 Mar 2008 20:49:49 -0400 (EDT) Original-Received: from VIRUSCAN-DAEMON.emroute3.ornl.gov by emroute3.ornl.gov (PMDF V6.3-x14 #31501) id <0JXN00L028YTUY@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 12 Mar 2008 20:49:49 -0400 (EDT) Original-Received: from moh-exc-006.main.intgin.net (moh-exc-006.main.intgin.net [12.151.36.183]) by emroute3.ornl.gov (PMDF V6.3-x14 #31501) with ESMTP id <0JXN00L4G8YSK3@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 12 Mar 2008 20:49:41 -0400 (EDT) X-Envelope-from: Blake.Brehl@anritsu.com X-MIMEOLE: Produced By Microsoft Exchange V6.5 Thread-Topic: SUMMARY: cron schedule fire only on last day of month Thread-Index: AciEbR44QGXP7UI/Qe2eCv4zooBfcAANKRCg Content-class: urn:content-classes:message X-Spam-Virus: No X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on spam4.ornl.gov X-Spam-Level: X-Qmail-Scanner-MOVED-X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 X-MS-Has-Attach: X-MS-TNEF-Correlator: Xref: news.gmane.org gmane.os.tru64.managers:9290 Archived-At: Received many great replies. Ended up going with the 1st received, some = really nice ksh scripts from the link Eric provided.=20 Thanks Everyone! Blake _____________________________ >From Eric Sisson: I suggest that you look at the following article: http://www.kingcomputerservices.com/unix_101/subtracting_dates.htm It is a web posting of an article that was published originally in a = print magazine called "SunWorld". This article contains a script "monthdays" that calculates how many days = are in each month; an adjacent script "yeardays" helps it account for = leap years. Using Unix command date +%Y%m%d to get the current date as, for example, 20080312 will allow you to enter command monthdays 20080312 to get the following result (continuing the example): 31 Command date +%d will tell you the current day of the month as, for example, 12 If the result of "monthdays" and of the second "date" command are equal, = then you are on the last day of the month. I hope this helps. Regards, Eric Sisson _________________________ >From Chris Wincentsen Hi Blake, I do this little "case" to check dates. You could modify this kind of = logic for your needs... #!/bin/ksh cur_day=3D`date "+%d"` cur_mon=3D`date "+%b"` cur_mon_day=3D`date "+%b %d"` date_var=3D"" # * Process last day of month... case "$cur_mon" in "Jan") date_var=3D" Jan 31" ;; "Feb") date_var=3D" Feb 29" check_29th=3D`last | grep -s " Feb 29"` if [ -z "$check_29th" ] then date_var=3D" Feb 28" fi ;; "Mar") date_var=3D" Mar 31" ;; "Apr") date_var=3D" Apr 30" ;; "May") date_var=3D" May 31" ;; "Jun") date_var=3D" Jun 30" ;; "Jul") date_var=3D" Jul 31" ;; "Aug") date_var=3D" Aug 31" ;; "Sep") date_var=3D" Sep 30" ;; "Oct") date_var=3D" Oct 31" ;; "Nov") date_var=3D" Nov 30" ;; "Dec") date_var=3D" Dec 31" ;; *) # * Problem, set error value and exit... echo " Problem setting date variable." date_var=3D"error" exit 1 ;; esac if [ "$date_var" =3D "$cur_mon_day" ] then # * Process last day of month... # submit job here fi ---------------------------------------- The Feb 29th processing probably needs work for what you want. I = actually look for the last day of the previous month, so I've changed my = logic to be closer to what you might need. Anyway, hope that helps! Chris ______________________________________________ >From Orjan Pettersson Don't know if it will compile on tru64 but = http://sourceforge.net/projects/yest is very helpful for date calculations in scripts -- =D6rjan ___________________________________________________ >From Franz Fischer typeset perlscript=3D' my $now=3Dtime(); my @today=3Dlocaltime($now); my @tomorrow=3Dlocaltime($now+86400); exit($today[4]=3D=3D$tomorrow[4]); ' if perl -e "${perlscript}"; then echo "last day of the month" fi Regards \franz _____________________________________________ >From Dr. Thomas Blinn Fairly easy to find the month name from the date. Fairly easy to build (by hand) a list of month names with the usual rule = set, that is, 30 days hath Sep Apr Jun and Nov, all the rest are 31 day = months except Feb for which you have to decide if it's a leap year (that = is whether the year is divisible by 4, the next one for which that won't = work isn't for another 200 years by which time you and I will be dead, = so use a Feb rule of "the last day is 28 unless the year is a multiple = of 4"), once you do that simple test (a case type logic may be easiest) = you should have the decision tree for "is this the last day of the = month". I haven't written the script logic for you, but that's the basis for it. = Of course, if it's not the last day of the month, just exit the script, = else keep going and do whatever needs to be done on the last day of the = month. If it's not time critical that the action happen some time like mid-day = it is easier to do the task in the first minute of the first day of the = month from the perspective of the first day of a new month always = immediately follows the last day/hour/minute of the prior month. Tom _________________________________________ >From James Sainsbury If you have gnu date installed its fairly simple TOMORROW=3D`date +%d -d tomorrow` if [ "$TOMORROW" -eq 1 ]; then # today is the last day of this month Failing that since you are in the US (where from our point of view it is = always yesterday:) you can try setting the TZ variable to timezone ~ 24 = hour ahead of yours. eg # if your timezone is GMT+7 then TOMORROW=3D`TZ=3DGMT-17 date +%d` You could work out the current offset from GMT for your locale and and = 24 hours in the script. -----Original Message----- From: Brehl, Blake=20 Sent: Wednesday, March 12, 2008 11:16 AM To: Tru64 Mailing List (tru64-unix-managers@ornl.gov) Subject: cron schedule fire only on last day of month Hi Admins, =20 I'd like to fire a job only on the last day of the month from crontab. = Using ksh and a crontab entry of=20 =20 1 3 28-31 * * /apps/scripts/lastdayfire =20 and have the script figure out which day is the last of the month. =20 Any ideas? =20 Here's a sample script that runs only on the 1st 2 days of the month. =20 1 2 1-14 * * /apps/scripts/1st2mondaysrunit =20 #!/bin/ksh # script name 1st2mondaysrunit DAYOFWK=3D`date +"%Ou"`; export DAYOFWK if [[ $DAYOFWK =3D 1 ]] then /apps/scripts/1st2mondaysrunit fi =20 =20 Best Regards, Blake =20 Tru64UNIX 5.1A sp1 GS80 =20 Blake Brehl Sys Admin/DBA Anritsu Company United States Morgan Hill, CA blake.brehl@anritsu.com