1834660 Members
2616 Online
110069 Solutions
New Discussion

Date command

 
SOLVED
Go to solution
Adi_7
Frequent Advisor

Date command

Do we have any command in HP that gives the number of seconds elapsed from 1st Jan 1970?
like "date +%s" in linux.

Thanks
6 REPLIES 6
Michael Tully
Honored Contributor

Re: Date command

These should work if you have perl.

$ perl -e 'print time;'

or

$ perl -e 'print time,"\n"'
Anyone for a Mutiny ?
Adi_7
Frequent Advisor

Re: Date command

Thanks so much.
It worked!!
Adi_7
Frequent Advisor

Re: Date command

okay, I ran that command with perl installed on the machine.
But I have another HP machine which doesnt have perl installed and this command didnt work there as you said.
Now I have a script which does the same thing.
But that only works for SUN.
#!/bin/sh

FILE=/temp/abcd.time

touch $FILE

(
echo 10 o 8 i
echo $FILE | /usr/bin/cpio -o -H odc 2>/dev/null | /usr/bin/cut -c50-59
echo p
) | /usr/bin/dc

/usr/bin/rm -f /tmp/abcd.time

For HP it gives the error as "Empty Stack".
How do I get over with this problem.
Any suggestions would help.
Thanks.
Gregory Fruth
Esteemed Contributor

Re: Date command

I guess the first question to ask is "why do you
want to do this"? Perhaps there's an easier
route to go.

It is relatively straightforward and portable to
write a short C program to get the time in the
format you want:

#include
#include

int main() {
printf("%d\n", time(NULL));
return(0);
}

Compile this and install it on the machine as
/usr/local/bin/gettimestamp or somesuch.
Then just call it from your script.

HTH
john korterman
Honored Contributor
Solution

Re: Date command

Hi Adi,

you can modify your script to something like this on hpux:

#!/usr/bin/sh
FILE=/tmp/abcd.time
touch $FILE
HEADER=$(echo $FILE | /usr/bin/cpio -o -c 2>/dev/null)
(
echo 10 o 8 i
echo "$HEADER" | /usr/bin/cut -c50-59
echo p
) | /usr/bin/dc
/usr/bin/rm -f /tmp/abcd.time

# end of script

On my system it gives this result:

1061711793

which can be converted it into something more human this way:
# SECS=1061711793
# echo 0d${SECS}=Y|adb
2003 Aug 24 09:56:33

regards,
John K.
it would be nice if you always got a second chance
H.Merijn Brand (procura
Honored Contributor

Re: Date command

If this is part of a large script(ing project) why not consider installing perl on all your systems? Than you have portable scripts by default :)

For HP-UX, you can get precompiled binaries from the HP Porting Centers (http://hpux.connect.org.uk/ amongst many) or my HP ITRC site (http://www.cmve.net/~merijn or https://www.beepz.com/personal/merijn). For Sun (and other OS's) links to precompiled binaries can be found here (http://www.cpan.org/ports/)

If possible, I'd advise you to take a recent port, like 5.8.0 (current latest stable), because that assures all examples posted here to actually work.

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn