Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Manipulation in .ksh script

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
We have some files which are maintained by the system using the format mmddyyyy.log (e.g., 03022005.log). I have a script which works just fine manually - I simply enter the 0302 as my only command line argument and it uses ${1} where needed to copy and work with the copy of the file.

I've now been told that this process 'must' be automated, i.e., that I have to make it a cron job so that the error reports it generates will go to the customer every day even weekends and holidays and so that I won't have to come in and run it on those days (which is a good thing as far as I'm concerned ...).

Anyway, I need some way to grab the current date, calculate the previous day's date as separate pieces (mm, dd and yyyy) and have it available to the script (I use the pieces in various ways to name the intermediate and error report files).

I've tried using the parameters of the date command but can't come up with a working way to get the correct values when I cross a month boundary (from Feb to Mar) or, I presume, when we go from 2005 to 2006 next January.

Thoughts? Comments? Pointers to an existing discussion?

Thanks in advance.

Tom

"My mind is like a steel whatchamacallit ...
 
faq80-4800 faq80-2236 faq80-953

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
a couple more:

thread822-445663 thread80-758168

my favorite is Julian2Gregorian conversion.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vlad:

Thanks a bunch - the Julian2Gregorian is a neat trick, wish I'd thought of it.

Goes to show that, no matter how long you work with these infernal machines, you can always learn something new.

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top