Solved

Calendar Calculator

Posted on 1998-04-29
9
262 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
Yes, please expand on the perl solution.

0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
Thanks again, just what i needed.



0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

763 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

9 Experts available now in Live!

Get 1:1 Help Now