The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 04:15 AM
performing a task at regular intervals mridula High Level Programming 2 11-14-2005 02:26 AM
mailing myself at regular intervals... timepassman Shell Programming and Scripting 4 08-21-2005 05:11 PM
How to perform Date Intervals? yongho Shell Programming and Scripting 2 06-21-2005 08:02 AM
Schedule a Batch file to delete files at particular intervals Indom Windows & DOS: Issues & Discussions 6 02-04-2004 09:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-29-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Date Intervals

I posted a question on date intervals about a month back asking about how I could be able to go about a user entering the starting year/month/day and an ending year/month/day and then the script automatically cycling through each day of each month of each year that the user has specified.

I checked out Perderabo's datecalc script and it was helpful but still not exactly what I needed.

I've thrown together some code today but I know that it's not going to work, I just need some suggestions on how I can complete this.

Code:
#!/bin/ksh

#                     Ja Fe Ma Ap My Jn Jl Au Se Oc No De
set -A DaysInMonth xx 31 28 31 30 31 30 31 31 30 31 30 31

isLeapYr=`date.isLeapYr.ksh`
if (( isLeapYr==1 )); then
    DaysInMonth[2]=29
fi

while (( start_date_Y < end_date_Y )); do

    while (( start_date_m < end_date_m )); do

        while (( start_date_d < ${DaysInMonth[${start_date_d}]} )); do
        (( start_date_d=start_date_d+1 ))
        done

        (( start_date_m=start_date_m+1 ))
    done

    (( start_date_Y=start_date_Y+1 ))
done
Some of my concerns are:
Take a look at the start_date_m < end_date_m loop (the 2nd while loop). What if the starting month is 4 and the ending month is 10 (but the user meant the 10 month of the 2nd year) then the loop will break prematurely.

How do I adjust for this?

I'm continuuing to work on this script, so I will keep this post updated.

Last edited by yongho; 07-29-2005 at 09:46 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 07-29-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Using Ruby:
Code:
require "date"

Date.new(2004,2,25).upto(Date.new(2004,3,2)) do  |date| 
  puts date.to_s
end
2004-02-25
2004-02-26
2004-02-27
2004-02-28
2004-02-29
2004-03-01
2004-03-02
Reply With Quote
  #3  
Old 07-29-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Hrm..

I'm not familiar with the code you just wrote.
Can that be done with korn shell?
Reply With Quote
  #4  
Old 07-29-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally Posted by yongho
I posted a question on date intervals about a month back asking about how I could be able to go about a user entering the starting year/month/day and an ending year/month/day and then the script automatically cycling through each day of each month of each year that the user has specified.

I checked out Perderabo's datecalc script and it was helpful but still not exactly what I needed.
This would take about 30 seconds to write if you would use datecalc. In fact....
Code:
#! /usr/bin/ksh

read "yr1?enter start date (yyyy mm dd) - " mo1 da1
start=$(datecalc -j $yr1 $mo1 $da1) ||
        { echo $yr1 $mo1 $da1 is not valid ; exit 1 ; }
read "yr2?enter start date (yyyy mm dd) - " mo2 da2
stop=$(datecalc -j $yr2 $mo2 $da2) ||
        { echo $yr2 $mo2 $da2 is not valid ; exit 1 ; }

while ((start<stop)) ; do
        datecalc -j $start
        ((start=start+1))
done
exit 0
Well, I'm getting old... OK, 110 seconds..
Reply With Quote
  #5  
Old 07-29-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Amazed.
Reply With Quote
  #6  
Old 07-29-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
I'm almost done with my version.

I'll post it up soon so people can compare the easy way (Your way) and the hard way (My way)
Reply With Quote
  #7  
Old 07-29-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Quote:
Originally Posted by yongho
I'm not familiar with the code you just wrote.
Can that be done with korn shell?
It's for the Ruby language, which is free and available for every platform.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0