Operating System - HP-UX
1829404 Members
1870 Online
109991 Solutions
New Discussion

Date calculation in shell

 
SOLVED
Go to solution
Diego Balgera
Frequent Advisor

Date calculation in shell

Hi,

could you please suggest a method in shell to add or subtract a certain number of days to a date, i.e. the date returned by the "date" command?

My environment is Hp-ux 11.0.

Thank you in advance!
Best regards.
Diego.
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: Date calculation in shell

Diego,

I would suggest you go to Merijn's site and download a version of A. Clay Stephenson's excellent clajd.sh script. Merijn's site can be found here:

http://www.cmve.net/~merijn/#Statistics


Pete

Pete
Vijaya Kumar_3
Respected Contributor

Re: Date calculation in shell

There are two famous methods for extracting the date from date command.

One method is using the following format:
# date +%Y
2004

Second method is using set command:
$ date
Fri Jan 30 06:21:34 EST 2004
$ set `date`
$ echo $1
Fri
$ echo $2
Jan
$ echo $3
30
$ echo $4
06:21:39
$ echo $5
EST
$ echo $6
2004

Hope this helps
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Pete Randall
Outstanding Contributor

Re: Date calculation in shell

Diego,

Here's another of Merijn's mirror sites, just in case cmve.net is unavailable:

http://www.hpux.ws/merijn/

It's all the way at the bottom of the page, described as "* A. Clay Stephenson's Date Hammer Shell version or Perl version"


Pete

Pete
Jean-Luc Oudart
Honored Contributor

Re: Date calculation in shell

Diego,

"calj.sh" could be found on the favourite script thread "favourite sysadmin scripts you always keep around...."

http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x026250011d20d6118ff40090279cd0f9%2C00.html&admit=716493758+1075462236234+28353475

Rgds,
Jean-Luc
fiat lux
Diego Balgera
Frequent Advisor

Re: Date calculation in shell

Hi,
thank you to everyone, your suggestions helped.
Bye!
Diego.