Sponsored Content
Full Discussion: Date Intervals
Top Forums Shell Programming and Scripting Date Intervals Post 79663 by yongho on Friday 29th of July 2005 12:39:38 PM
Old 07-29-2005
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 01:46 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to perform Date Intervals?

I have a 300 line script which generates key performance indicators for one of our systems. Since I just started learning sh/ksh half a month ago there's still a lot I haven't had experience with yet. Currently, the script generates the report for a specific day. (It takes the date specified by... (2 Replies)
Discussion started by: yongho
2 Replies

2. Shell Programming and Scripting

mailing myself at regular intervals...

hi all, i wrote a script to mail myself using pine (modified) to keep remind of b'days. #!/bin/bash grep "`date +%D |awk -F/ '{print $2+1, $1+0}'`" dataFile >/home/username/mailme if test -s /home/username/mailme then pine -I '^X,y' -subject "Birthday Remainder" username... (4 Replies)
Discussion started by: timepassman
4 Replies

3. Programming

performing a task at regular intervals

hi! i m tryin to write a program that will perform a specific tasks after fixed interval of time.say every 1 min. i jus donno how to go abt it.. which functions to use and so on... i wud like to add that i am dont want to use crontab over here. ny lead is appreciated. thanx. (2 Replies)
Discussion started by: mridula
2 Replies

4. Red Hat

How do sa1/sar time intervals work?

Hi, I have set up sar on my RedHat and Fedora Linux systems. I am running sa1 from cron: 0 8-17 * * 1-5 /usr/lib/sa/sa1 1200 3 & The 1200 and 3 parameters tell sa1 to save data every 1200 seconds (== 20 minutes) and to write 3 times. When I run sar to observe my data, I'll see... (1 Reply)
Discussion started by: mschwage
1 Replies

5. Shell Programming and Scripting

Bash loop script for specfic intervals

Hello, first of all I am happy to sign up here. Next is, I have shell scripts for all the files I want looped infinitely for specific intervals(This is for a wmii config). My question here is how can I run multiple scripts at a 10 second interval for instance? (4 Replies)
Discussion started by: Mesher
4 Replies

6. Shell Programming and Scripting

Shell Script - Copy File at intervals

Hi, I want to copy some files from a Folder say, /usr/X at random intervals to another location. Basically, new files will be dumped at random intervals to location /usr/X and I have to copy those new files to some other location (after copying, I cannot delete those files from source... (2 Replies)
Discussion started by: angshuman_ag
2 Replies

7. Shell Programming and Scripting

Divide numbers into intervals

divide input values into specified number (-100 or -200) according to the key (a1 or a2 ....) For ex: if we give -100 in the command line it would create 100 number intervals (1-100, 100-200, 200-300) untill it covers the value 300 in a1. Note: It should work the same even with huge numbers... (3 Replies)
Discussion started by: ruby_sgp
3 Replies

8. Shell Programming and Scripting

Grab exactly one byte from a FIFO, at random intervals

I want to develop a script of the following form: #!/bin/bash # Function 'listen' opens a data stream # which stores all incoming bytes in # a buffer, preparing them to be # grabbed by a following function # which appears at random # intervals during the execution of # the script ... (11 Replies)
Discussion started by: vomv1988
11 Replies

9. UNIX for Dummies Questions & Answers

Building intervals

Hi all, I hope you can help me with the following question: I have multiple tables like this: Chr Start End Zygosity Gene chr1 153233510 153233510 het LOR chr1 153233615 153233615 hom LOR chr1 153233701 153233701 hom LOR chr1 ... (5 Replies)
Discussion started by: lsantome
5 Replies

10. UNIX for Dummies Questions & Answers

Gap length between intervals

hi all, I wish to calculate the length between intervals whose are defined by a starting and an end possition. The data looks like this: 1 10 23 30 45 60 70 100... The desired output should be: 13 # (23-10) 15 # (45-30) 10 # (70-60)... I donīt know how to operate with different... (2 Replies)
Discussion started by: lsantome
2 Replies
GMMKTIME(3)								 1							       GMMKTIME(3)

gmmktime - Get Unix timestamp for a GMT date

SYNOPSIS
int gmmktime ([int $hour = gmdate("H")], [int $minute = gmdate("i")], [int $second = gmdate("s")], [int $month = gmdate("n")], [int $day = gmdate("j")], [int $year = gmdate("Y")], [int $is_dst = -1]) DESCRIPTION
Identical to mktime(3) except the passed parameters represents a GMT date. gmmktime(3) internally uses mktime(3) so only times valid in derived local time can be used. Like mktime(3), arguments may be left out in order from right to left, with any omitted arguments being set to the current corresponding GMT value. PARAMETERS
o $hour - The number of the hour relative to the start of the day determined by $month, $day and $year. Negative values reference the hour before midnight of the day in question. Values greater than 23 reference the appropriate hour in the following day(s). o $minute - The number of the minute relative to the start of the $hour. Negative values reference the minute in the previous hour. Values greater than 59 reference the appropriate minute in the following hour(s). o $second - The number of seconds relative to the start of the $minute. Negative values reference the second in the previous minute. Values greater than 59 reference the appropriate second in the following minute(s). o $month - The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s). o $day - The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) refer- ence the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). o $year - The year o $is_dst - Parameters always represent a GMT date so $is_dst doesn't influence the result. Note This parameter has been removed in PHP 7.0.0. RETURN VALUES
Returns a integer Unix timestamp. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 7.0.0 | | | | | | | $is_dst parameter has been removed. | | | | | 5.1.0 | | | | | | | As of PHP 5.1.0, the $is_dst parameter became | | | deprecated. As a result, the new timezone han- | | | dling features should be used instead. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 gmmktime(3) basic example <?php // Prints: July 1, 2000 is on a Saturday echo "July 1, 2000 is on a " . date("l", gmmktime(0, 0, 0, 7, 1, 2000)); ?> SEE ALSO
mktime(3), date(3), time(3). PHP Documentation Group GMMKTIME(3)
All times are GMT -4. The time now is 01:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy