Operating System - HP-UX
1847942 Members
3405 Online
104021 Solutions
New Discussion

Re: Date×tamp use in scripts

 
Maarten van Maanen
Regular Advisor

Date×tamp use in scripts

I want to use a date variable in a (crontab-script to monitor performance of our AutoRAID 12h system (arraydsp -r and arraydsp -m).
The required dates are the current date and timestamp as well as the same variable from an earlier period.
The required format is mmddhhmm (month, day, hour, minutes). I can get date + time with the date +%m%d%H%M command but have to gave an older time and date as well.
How can I perform a calculation using date to get, for example, the current date and time minus six hours.
3 REPLIES 3
Andreas Voss
Honored Contributor

Re: Date×tamp use in scripts

Hi,

i think this job goes only with a little C programm. I put it at the attachment.
Save the C source into pasttime.c and compile with cc pasttime.c -o pasttime

Usage: pasttime

The output is what you want to get for arraydsp.

Cheers

Andrew
John Palmer
Honored Contributor

Re: Date×tamp use in scripts

The (not so) easy way is to convert your date/times to binary seconds, do your arithmetic and then convert them back to date/time.

How is your C programming? man ctime gives details on the functions that you need (localtime, time etc).

If C is not your forte, it could also be done in Perl.

Regards,

John
Rick Garland
Honored Contributor

Re: Date×tamp use in scripts

DAY=`TZ=MST+17MDT date +%d%H%M`

Will give previous 24 hrs hours in MST. You will have to play with and modify your TZ
value.