- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Date Calculations
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 11:34 AM
07-18-2002 11:34 AM
Thanks to some assistance from you guys, I have been able to join some files to produce output data like this:
1009 1-Jan-1999 12-Jun-1999
2063 24-Oct-2001 12-Dec-2001
3741 12-Feb-2002 ----------
The first field is a unique ID No. The second field is a start date and the third field is an ending date. What I need to do is find those lines which have the dashed ending date field. They are still active. I think I can do that but the hard part is to then determine if the starting date is about to expire. I want to issue a warning 1 week before the 90 day period is up. Basically, I need something that will work if today's date - starting date >= 83 days. I want to output the ID no. and the days left on one line.
I am trying to replace several C programs with scripts. I've looked at the date command but I am concerned about the calculations where the year changes.
Thanks in advance for any and all help,
Derek Card
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 11:45 AM
07-18-2002 11:45 AM
SolutionWhenever I see date calculations, I perk up. This actually seems easy with my date sledgehammer, caljd.sh.
#!/usr/bin/sh
TODAY=$(caljd.sh)
MAXDAYS=83
while read ID START_DATE END_DATE
do
X=$(echo "${END_DATE}" | tr -d "-")
if [[ -z "${X}" ]]
then
JD_START_DATE=$(caljd.sh -e -i -S '-' -c ${START_DATE})
DAYS=$((${TODAY} - ${JD_START_DATE}))
if [[ ${DAYS} -ge ${MAXDAYS} ]]
then
echo "${ID}\t${DAYS}"
fi
fi
done
exit 0
--------------------------------------
You would use it like:
expire.sh < myfile > newfile
If I haven't made a typo that should do it.
Here's caljd.sh. caljd.sh -u will give full usage including a number of examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 12:02 PM
07-18-2002 12:02 PM
Re: Date Calculations
You can also use the Perl version, caljd.pl. The arguments are exactly the same. In looking over my earlier example, I realized that you could put a grep "--------" in front of it and make it faster.
Here's caljd.pl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 12:24 PM
07-18-2002 12:24 PM
Re: Date Calculations
Thanks but there seems to be something wrong with your script. I had already searched and found caljd.sh. I keep getting an error message: /usr/bin/caljd.sh Invalid args. Any ideas?
Derek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 12:31 PM
07-18-2002 12:31 PM
Re: Date Calculations
I don't see anything wrong but I just typed this guy in 'off the cuff' so I could have very well missed a pesky '{' or '(' but it's not jumping out at me.
You mention that you did a search. As a guess, are you using a version < 2.1? The -c, -i, and -I options to allow it to recognize dates like 1-January-2002 were not added until Version 2.1. I hope it's that; otherwise, it's my advanced one-finger hunt-and-peck typing technique but again I don't see that in my earlier posting.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 12:44 PM
07-18-2002 12:44 PM
Re: Date Calculations
I don't see any typos either. That is usual, you almost always have at least one. :-) Maybe you are just getting more sneaky.
:-)
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 12:55 PM
07-18-2002 12:55 PM
Re: Date Calculations
Thanks again,
Derek