Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Generic shell function to display dates from existing system date (given current date)  (for hpux, solaris and linux)

Posted on 2014-01-19
5
Medium Priority
?
434 Views
Last Modified: 2014-01-19
I need a ascript that can help to find the last day of the previous month by given a current date in all above server OS.

For example, if cuurent date = '20/Mar/2013'
result of  "last_date = X_function" will be 28/Feb or 29/Feb depending on the year

For example, if cuurent date = '22/Mar/2013'
result of  "last_date = X_function" will be 28/Feb or 29/Feb depending on the year

if current date = '23/Jan/2014'
result of  "last_date = X_function" will be 31/Dec/2014

if current date = '03/Jan/2014'
result of  "last_date = X_function" will be 31/Dec/2014

perl calling is allowed, but has to be generic so that the perl calling can work in all above server OS.
0
Comment
Question by:tindavid
5 Comments
 
LVL 10

Expert Comment

by:lanboyo
ID: 39793263
Linux is easier than most because date is a lot better.

The key is always the unix époq

NOW=$( date +%s )
DOM=$( date +%d )
   # to figure out what the unix époq was the last day of last month, we would subtract the day of the month * number of seconds in a day from the current époq
LESS=$((  $DOM * 60 * 60 *24 ))
ELDOM=$(( $NOW - $LESS ))
OUTPUT= $( echo $ELDOM  | date -p +%d/%b/%Y )
echo $OUTPUT


Solaris is kind of icky, to get the current époq you have to do backflips. I will copy what I did for a different script if no one hits it first.
0
 
LVL 10

Expert Comment

by:lanboyo
ID: 39793273
Seriously I have greped out the output of the date command thru the adb debugger to get the époq. Honestly, what a pain, the system is clearly using it internally, but the date command won't expose it for me in Solaris.
0
 
LVL 27

Expert Comment

by:wilcoxon
ID: 39793306
What do you mean by the below?
perl calling is allowed, but has to be generic so that the perl calling can work in all above server OS.
Is it allowable to use perl modules not in the core?  What version of perl do you have installed on the machines?
0
 

Author Comment

by:tindavid
ID: 39793352
We have Oracle software (9i - 11g)  installed in most of the servers, therefore a perl version that comes with Oracle software will do.
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 39793444
perl -le '($h,$d)=(localtime)[2,3]; print join"/",(split/ /,localtime time-($d*24+$h-12)*60*60)[2,1,4];'
will work across daylight saving time switchover
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I wrote an article (http://www.experts-exchange.com/articles/2245/Anti-rootkit-software.html) some time ago with a reference to nLite  (http://www.nliteos.com/)slipstreaming software.  I recently changed that link to point to NTLite (https://www.ntl…
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

916 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