Solved

Calendar Calculator

Posted on 1998-04-29
9
263 Views
Last Modified: 2013-12-03
I am in need of some sort of calendar calulator.  From within a shell script i set a variable to a date by using the date command.  I then need to be able to set another variable to a date that is 2 weeks ( 14 days) later.  I will then compare this new date to the current date to determine if this item is overdue.  I would then issue some kind of email message to the particular party.  Is there such a tool available, or is it possible all within shell scripts?
0
Comment
Question by:j_k
  • 5
  • 4
9 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2006540
I don't understand what you want to do.
If you set a variable to the current date, and another variable to a date 14 days later, then don't you already know how they compare?

0
 

Author Comment

by:j_k
ID: 2006541
Hello Ozo,

Sorry, The second date variable would have to be calculated from value of the 1st date variable that was contained in a text file.  Example: something like this!

The data file would look something like this:
submittal1|04/20/98|
submittal2|04/24/98|
submittal3|04/28/98|
... and so on ....

and the script would do something like this:
for each LINE in data file

SUBMITTAL=??? (awk on LINE getting 1st column)
ENTERED_DATE=04/20/98 (awk on LINE getting 2nd column)
RESPOND_DATE=???  (a calculated date 2 weeks after the entered_date)

if (today's date) is > respond_date then
  send email notifying user that the submittal $SUBMITTAL
  that was due on $RESPOND_DATE is overdue

Hope this helps
JAK


0
 
LVL 84

Expert Comment

by:ozo
ID: 2006542
I could suggest an answer, but I'm afraid you may have a problem with it about 600 days later...
0
 

Author Comment

by:j_k
ID: 2006543
Thats Ok, This program may be need then.  But for now it
sure would be helpful, in the ways we are doing things now!.

Is this a good place for perl?

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 84

Expert Comment

by:ozo
ID: 2006544
Yes, using Time::Local::timelocal in perl would have been one of my suggestions.
(Setting a large time zone offset or Zeller's congruence would have been the others)

I have to go for now, but I'll try to be back later if you need more specific help.
0
 

Author Comment

by:j_k
ID: 2006545
Yes, please expand on the perl solution.

0
 
LVL 84

Expert Comment

by:ozo
ID: 2006546
use Time::Local;
$now = time;
while( <> ){
        ($ss,$mm,$dd,$yy)=split('[/|]');
        $due = timelocal(0,0,6,$dd,$mm-1,$yy)+60*60*24*14;
        next if $due > $now;
        ($date=localtime($due))=~s/ \d\d:\d\d:\d\d/,/;
        open(M,"|/usr/lib/sendmail -t") || warn $!;
        print M "To: $user\nSubject: overdue\n\nsubmittal $ss that was due on $date is overdue\n";
        close M || warn $!;
}
0
 

Author Comment

by:j_k
ID: 2006547
Thanks again, just what i needed.



0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 2006548
Ok, shall we call it an Answer then?

BTW, except for generating the "due on $date" part of the message
you might even have gotten by without using Time::Local
with something like:

($dd,$mm,$yy)=(localtime time-60*60*24*14)[3,4,5];
$old = sprintf"%d%02d%02d",$yy+1900,$mm+1,$dd;
while( <> ){
    ($ss,$mm,$dd,$yy)=split('[/|]');
    next if $old < sprintf"%d%02d%02d",$yy+1900,$mm,$dd;
    open(M,"|/usr/lib/sendmail -t") || warn $!;
    print M "To: $user\nSubject: overdue\n\nsubmittal $ss that was due 14 days after $mm/$dd/$yy is overdue\n";
    close M || warn $!;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now