![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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-26 2004-02-27 2004-02-28 2004-02-29 2004-03-01 2004-03-02 |
|
#3
|
|||
|
|||
|
Hrm..
I'm not familiar with the code you just wrote.
Can that be done with korn shell? |
|
#4
|
||||
|
||||
|
Quote:
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
|
|
#5
|
|||
|
|||
|
|
|
#6
|
|||
|
|||
|
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) |
|
#7
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |