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
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 26

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 84

Accepted Solution

by:
ozo earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

617 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