Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining timestamp 2

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

How can I obtain the current TIMESTAMP in HP-UX ? man data doesnt give any info on this..

thnx,
 
Something like this ?
date '+%Y-%m-%d %T'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
But this gives the date-time.. (2005-04-04 11:41:23). I want the timestamp .. something like '1112612700'.

thnx
 
Hi,

I presume 'timestamp' means 'seconds since 1 Jan 1970' ?
Sorry, I don't know a pure Unix way to get it. Perhaps somebody else does?
I only know of a way to do it in a C program. It requires some understanding of structs. (I haven't a code example though.)
How good is your C?
 
hmm.. strange that Unix doesnt have any command to obtain the Timestamp :(

My objective is the following:

I want to execute a script only if it is 30 minutes older/ later than the last time it was executed.

How can I accomplish this ? I thought of using timestamps but.....

thnx
 
the first idea:
use cron to run it every 30 minutes?
 
nope.. cant use cron because of further validations I hv to perform.. it has to be 30 minutes after every execution and not every 30 minutes..

hv very little knowledge of perl.. how do I use the above perl code ?

thnx
 
got it..

perl -e 'print time . "\n"' give the reqd timestamp..

thnx
 
write a perl script and save it in /usr/local/bin

timestamp (file)
------------------
#!/usr/bin/perl
print time . "\n"
----------------------

chmod 777 /usr/bin/timestamp

Cheers.
 
You may also consider at now +30 minutes

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
another question...

Can I store the output of the perl command into a variable for further manipulation ??

something like

TEMPVAL = perl -e 'print time'

if TEMPVAL -gt 300 .........

I tried the above but its not working..
thnx,
 
In ksh-like:
TEMPVAL=$(perl -e 'print time')
In traditional bourne-shell:
TEMPVAL=`perl -e 'print time'`


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
one last question..

how do I capture the output of another file into a variable ?

something like

OLDVAL = cat tempData

which is not working

thnx again
 
In ksh-like:
OLDVAL=$(<tempData)
In traditional bourne-shell:
OLDVAL=`cat tempData`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello again,

I have a urgent question and hope someone here can help me..

perl -e 'print time' in HP-UX gives me the fwg TIMESTAMP '1112778096' which corresponds to 'Wed, 6 Apr 2005 09:01:36 UTC'

At the sametime, command DATE gives me the date as 'Wed Apr 6 10:02:05 PST 2005'

Which of the above 2 is correct ? and why ?

thanks,
 
Maybe both are correct.
UTC aka GMT is Unix standard time.
The other must be your local time. What is the output of 'echo $TZ'? Which time zone do you live in? I presume PST, in this case, does not mean 'Pacific Standard Time'?
hope this helps
 
I suspect that technically both are correct. The problem is how the data is interpreted. The number of seconds since 1 Jan 1970 doesn't take into account "Timezones" or "British Summer Time" etc, whereas the date command does.

Could I suggest using the command:
timestamp=`date +'%Y%m%d%H%M%S'`
(produces for example 20050406102521 at 10:25 [21 secs] on 06 Apr 2005)

I hope that helps.

Mike
 
'echo $TZ' returns PWT0PST, so as hoinz said, it appears to be Pacific Standard Time.

Basically what I need to know is, is this a cause for worry.. The machine is our Production machine and a lapse of 1 hour can cause untold problems..

I just want to be assured that the date used is the one thats obtained from the DATE command and not the TIMESTAMP. I am in Lisbon (local time = GMT). I figure the TIMESTAMP obtained doesnt take into account the DST observed here..

thnx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top