tindavid
asked on
Generic shell function to display dates from existing system date (given current date) (for hpux, solaris and linux)
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.
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.
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.
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?
ASKER
We have Oracle software (9i - 11g) installed in most of the servers, therefore a perl version that comes with Oracle software will do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.