-- Örjan ___________________________________________________ >From Franz Fischer typeset perlscript=' my $now=time(); my _at_today=localtime($now); my _at_tomorrow=localtime($now+86400); exit($today[4]==$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=`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=`TZ=GMT-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 Sent: Wednesday, March 12, 2008 11:16 AM To: Tru64 Mailing List (tru64-unix-managers_at_ornl.gov) Subject: cron schedule fire only on last day of month Hi Admins, I'd like to fire a job only on the last day of the month from crontab. Using ksh and a crontab entry of 1 3 28-31 * * /apps/scripts/lastdayfire and have the script figure out which day is the last of the month. Any ideas? Here's a sample script that runs only on the 1st 2 days of the month. 1 2 1-14 * * /apps/scripts/1st2mondaysrunit #!/bin/ksh # script name 1st2mondaysrunit DAYOFWK=`date +"%Ou"`; export DAYOFWK if [[ $DAYOFWK = 1 ]] then /apps/scripts/1st2mondaysrunit fi Best Regards, Blake Tru64UNIX 5.1A sp1 GS80 Blake Brehl Sys Admin/DBA Anritsu Company United States Morgan Hill, CA blake.brehl_at_anritsu.comReceived on Thu Mar 13 2008 - 00:50:43 NZDT
This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:45 NZDT