Solved

Calendar Calculator

Posted on 1998-04-29
9
265 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

831 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