Operating System - Linux
1748081 Members
5338 Online
108758 Solutions
New Discussion

datecalc -utility in unix

 
rveri-admin
Frequent Advisor

datecalc -utility in unix

Hi Experts,

We have a script from hp-ux and needs to be migrate to linux  (redhat )platform,

The existing script in hp-ux is using maestro job scheduler ,  and using an utility called datecalc ,

 

However on linux side it will not be used maestro application , so the datecalc program is not there .

 

Here is from the hp-ux system:  The line in the batch script looks like:

 

####

export TODAY=`date "+%Y%m%d.%H%M"`

...

export datecalc=`/opt/maes100/maestro/bin/datecalc today -1 days pic yyyy.mm.dd`

...

###

 

 

 

Question:  How to migrate this portion, What kind of utility or command need to use to convert similar date format in linux. Is there anything available to convert date in linux like datecalc utility.

 

Thanks in advance,

 

5 REPLIES 5
donna hofmeister
Trusted Contributor

Re: datecalc -utility in unix

you are going to need to "roll your own".

 

i suggest the perl module date::calc -- works great

http://search.cpan.org/~stbey/Date-Calc-6.3/lib/Date/Calc.pod

Dennis Handly
Acclaimed Contributor

Re: datecalc - utility in Linux

rveri-admin
Frequent Advisor

Re: datecalc - utility in Linux

Thanks both,

 

Dennis,

I tried to use the caljd.sh in linux,  I changed the shell in the first line of the script from /usr/bin/sh   to  /bin/bash , but getting error , in getting the YESTARDAY_DATE :

 

 

sh-3.2$ YESTERDAY_DATE=$(caljd -s -y $(caljd -p 1))
./caljd: line 116: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
./caljd: line 118: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
./caljd: line 124: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
sh-3.2$

 

any suggesion.

 

Thanks

Dennis Handly
Acclaimed Contributor

Re: datecalc - utility in Linux

>I tried to use the caljd.sh in Linux,

 

Try the perl version as it should be more portable.

 

I also ran into the lack of -Z in typeset when I ported a script to bash.

rveri-admin
Frequent Advisor

Re: datecalc - utility in Linux

Thanks,   Since it is linux , there are lot of flexibility for date command , and I found a good one.

 

Very simple:  $ date -d yesterday

 

$ date -d yesterday
Sun Jul  1 15:43:29 MDT 2012

 

 

 

# Todays Date:

$ date "+%Y.%m.%d"
2012.07.02

 

# Yesterdays Date:

$ date "+%Y.%m.%d" -d yesterday
2012.07.01

 

 

its so cool...