02-13-2018
In addition to what RudiC has already said, you say that you have messed up the loops; but there aren't any loops in your code! There are only nested if statements that seem to try to calculate the number of days in years without accounting for the number of days in months or the number of days between days within a month. You are correct in thinking that you need a couple of nested loops (one looping through months and one looping through years, and depending on how you structure your code, you might also want a loop to loop through days in a month), but your code does not contain any loops at all. Loops start with keywords like for, until, and while; not with the keyword if.
One might note that the prompts given to your users asks for 10 character inputs in the format YYYY-MM-DD, but when you extract the year, month, and day fields from the entered strings, you only look at the first 8 of those 10 characters.
RudiC mentioned that you have a dangling else. I'm not sure it that is true or not. Your lack of consistent indentation makes it impossible to line up ifs with their corresponding elses and fis. But it is clear that you have more fis than you have ifs; and that has to be an error.
Instead of partially checking whether the start date comes before or after the end date so many times, you might want to check that just after you get the two dates from your user and switch their values if the end comes before the start.
Note also that if you have a date like December 31 in one year and January 1 in the next year, there is one day between them whether or not either of those years is a leap year. And, if you go from February 28 to March 1 that is going to be one day or two days depending on what year is being processed. Your code only calculates leap days if the years are different. And, if you go from March 1 in one leap year to February 28 in the next leap year; even though both years are leap years, there are no leap days in the four or eight years between those two dates.
And, finally, you might also note that you use a variable named start, but you never assign any value to it. I haven't verified that there aren't any other variables that are used without being set.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am currently running the following Korn shell script which works fine:
#!/usr/bin/ksh
count=`db2 -x "select count(*) from schema.tablename"`
echo "count"
I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies
2. Shell Programming and Scripting
In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line.
I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies
3. Shell Programming and Scripting
Hi! I am trying to read a file and every line has a specific date as one of its fields.
I want to take that date and compare it to the date today plus 6 days.
while read line
do
date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD
if ; then
...proceed commands
... (1 Reply)
Discussion started by: kokoro
1 Replies
4. UNIX for Dummies Questions & Answers
date --date='10:30am + 1 hour' +%H:%M
11:30 produces
date --date='10:30pm + 1 hour' +%H:%M produces
23:30
I want to do the following:
TIME="1:30pm"
date --date='$TIME + 1 hour' + %H:%M
to produce
14:30 (1 Reply)
Discussion started by: efittery
1 Replies
5. Shell Programming and Scripting
Hi ALL,
I was looking out for any freeware tool which can compare config properties of 2 linux machines for ex java properties.
Tried in Google but no luck.
Any help would be greatly appreciated :) (3 Replies)
Discussion started by: nikhil jain
3 Replies
6. Shell Programming and Scripting
hi all,
How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt
how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies
7. Shell Programming and Scripting
I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this,
Not After : Jul 28 14:09:57 2017 GMT
So I only crop out the date, with this command
echo $dateFile | cut -d ':' -f 2,4The result would be
Jul 28 14:57 2017 GMT
How do I... (3 Replies)
Discussion started by: Loc
3 Replies
8. UNIX for Beginners Questions & Answers
Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt .
I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies
9. UNIX for Beginners Questions & Answers
I have two files to be compared to get the output of the differences.
File1 has a lot more lists than File2.
After searching a lot on this thread I'am unable to find the exact code that im willing to get.
This will be used as 'pre-check'/post-check utility (health check Tool) to compare... (1 Reply)
Discussion started by: GeekyJimmy
1 Replies
10. UNIX for Beginners Questions & Answers
Hi Community!
Following on from this code in another thread:
#!/bin/bash
file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'`
file_date=`/bin/date -d "$file_string"`
file_epoch=`/bin/date -d "$file_string" +%s`
now_epoch=`/bin/date +%s`
if
then
#let... (2 Replies)
Discussion started by: Greenage
2 Replies
LEARN ABOUT DEBIAN
ods-timing
ods-timing(5) OpenDNSSEC timinig ods-timing(5)
NAME
ods-timing - OpenDNSSEC timing specification
SYNOPSIS
/etc/opendnssec/conf.xml
/etc/opendnssec/kasp.xml
/etc/opendnssec/zonelist.xml
DESCRIPTION
The configuration files of OpenDNSSEC need to have timing descriptions, notably for periods. These descriptions follow ISO 8601 with
exceptions for the duration of a month and a year, as these periods would be allowed to vary if ISO 8601 were strictly adhered to.
Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S. In these representations, the [n] is replaced by the value for each of
the date and time elements that follow the [n]. Leading zeros are not required. The capital letters P, Y, M, W, D, T, H, M and S are desig-
nators for each of the date and time elements and are not replaced
P is the duration designator (historically called "period") placed at the start of the duration representation.
Y is the year designator that follows the value for the number of years.
M is the month designator that follows the value for the number of months.
W is the week designator that follows the value for the number of weeks.
D is the day designator that follows the value for the number of days.
T is the time designator that precedes the time components of the representation.
H is the hour designator that follows the value for the number of hours.
M is the minute designator that follows the value for the number of minutes.
S is the second designator that follows the value for the number of seconds.
For example, P3Y6M4DT12H30M5S represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five sec-
onds". Date and time elements including their designator may be omitted if their value is zero, and lower order elements may also be omit-
ted for reduced precision. For example, P23DT23H and P4Y are both acceptable duration representations.
EXCEPTION
A year or month vary in duration depending on the current date. For OpenDNSSEC, we assume fixed values
One month
is assumed to be 31 days.
One year
is assumed to be 365 days.
This exception may or may not change in future releases of OpenDNSSEC. The reason for making this exception is to avoid complicating this
software in a way that may not meet any practical need.
SEE ALSO
ods-auditor(1), ods-control(8), ods-enforcerd(8), ods-hsmspeed(1), ods-hsmutil(1), ods-kaspcheck(1), ods-ksmutil(1), ods-signer(8),
ods-signerd(8), opendnssec(7), ISO 8601, http://www.opendnssec.org/
AUTHORS
OpenDNSSEC was made by the OpenDNSSEC project, to be found on http://www.opendnssec.org/
OpenDNSSEC February 2010 ods-timing(5)