Unix Shell - Epoch time

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2004 > Epoch time





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Epoch time
Gnarlodious

2004-04-18, 10:42 am

Is there a shell command to return seconds since 1/1/1970?

Google shows several years worth of hemming & hawing over the issue.

Or is there some module I can download?

The reason is, Apache's dynamic logfiles.

Thanks

-- Gnarlie

James Willmore

2004-04-18, 10:42 am

On Sat, 17 Apr 2004 03:31:39 +0000, Gnarlodious wrote:

> Is there a shell command to return seconds since 1/1/1970?
>
> Google shows several years worth of hemming & hawing over the issue.
>
> Or is there some module I can download?
>
> The reason is, Apache's dynamic logfiles.


If you have the GNU version of the `date` command:

date +%s

If you want, you could try using PERL :-) There are *many* different ways
to use/print/etc time. The quick and dirty one-liner is:

perl -e 'print time,"\n"'

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Let He who taketh the Plunge Remember to return it by Tuesday.


Peter J. Acklam

2004-04-18, 10:42 am

James Willmore <jwillmore@remove.adelphia.net> wrote:

> The quick and dirty one-liner is:
>
> PERL -e 'print time,"\n"'


$ PERL -le 'print time'
1082194446

I don't see anything dirty about this.

Peter

--
Peter J. Acklam - pjacklam@online.no - http://home.online.no/~pjacklam
James Willmore

2004-04-18, 10:42 am

On Sat, 17 Apr 2004 11:35:04 +0200, Peter J. Acklam wrote:

> James Willmore <jwillmore@remove.adelphia.net> wrote:
>
>
> $ PERL -le 'print time'
> 1082194446
>
> I don't see anything dirty about this.


Point taken.

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
... Logically incoherent, semantically incomprehensible, and
legally ... impeccable!

Randal L. Schwartz

2004-04-18, 1:33 pm

[vbcol=seagreen]

Peter> I don't see anything dirty about this.

OK, so it's just quick. Not dirty. Rather clean, in fact.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment PERL training!
Stefan Monnier

2004-04-19, 2:35 pm

> $ PERL -le 'print time'
> 1082194446


> I don't see anything dirty about this.


Well, using `perl' generally qualifies as being dirty.


Stefan
Heiner Steven

2004-04-19, 4:34 pm

Gnarlodious wrote:

> Is there a shell command to return seconds since 1/1/1970?


Presenting Stephane's idea:

awk 'BEGIN {srand(); print srand()}'

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
joe@invalid.address

2004-04-25, 3:34 pm

Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:

> Is there a shell command to return seconds since 1/1/1970?


This has come up enough that I've added the following to the FAQ under
the date arithmetic section:

h. Getting the number of seconds since the epoch

GNU date has the %s format option which returns the epoch
time. More portably, use awk

awk 'BEGIN {srand();print srand()}'

This works because srand() sets its seed value with the current
epoch time if not given an argument. It also returns the
previous seed value, so the second call gives the epoch time.

Depending on scheduling, when the call is actually executed,
etc, this might be off by a second.

Another way is to use PERL if you have it.

perl -e 'print time,"\n"'

Comments would be welcome before committing this.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Stefan Monnier

2004-04-25, 7:34 pm

> This works because srand() sets its seed value with the current
> epoch time if not given an argument. It also returns the
> previous seed value, so the second call gives the epoch time.


Is this guaranteed by POSIX or somesuch, or does it just happen to work
that way on 90% of the systems ?


Stefan
Chris F.A. Johnson

2004-04-25, 7:34 pm

On Sun, 25 Apr 2004 at 22:56 GMT, Stefan Monnier wrote:
>
> Is this guaranteed by POSIX or somesuch, or does it just happen to work
> that way on 90% of the systems ?


From the POSIX man page:

srand([expr])
Set the seed value for rand to expr or use the time of day if
expr is omitted. The previous seed value shall be returned.


<http://www.opengroup.org/onlinepubs...lities/awk.html>

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
John W. Krahn

2004-04-25, 8:34 pm

joe@invalid.address wrote:
>
> Another way is to use PERL if you have it.
>
> PERL -e 'print time,"\n"'
>
> Comments would be welcome before committing this.


You can reduce that to 15 characters if you want to be really obscure.
:-)

perl -leprint$^T



John
--
use Perl;
program
fulfillment
joe@invalid.address

2004-04-25, 11:34 pm

"John W. Krahn" <krahnj@acm.org> writes:

> joe@invalid.address wrote:
>
> You can reduce that to 15 characters if you want to be really
> obscure. :-)
>
> PERL -leprint$^T


That's kind of cool, I have to admit. Still, I feel some
responsibility to make the FAQ more or less understandable :-)

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
joe@invalid.address

2004-04-26, 12:35 pm

Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:

> Entity joe@invalid.address spoke thus:


> Is this poll about finding a method that works on all OS's?


No, just asking for comments. Someone might have another method that
wasn't shown, or might see a mistake in what I'm about to
add. Feedback is a good thing.

> I'm a little befuddled. Using the first suggestion: date +%s in OSX
> and it works.
>
> Nothing obscure about that. Or isn't it "portable"?


It's specific to GNU date. GNU date itself is pretty portable, but
it's not always available. Sometimes we have to deal with what's there
and can't install other stuff like this, so the FAQ tries to show
multiple ways of doing things (especially portable methods).

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Alan Connor

2004-04-26, 1:34 pm

On Sun, 25 Apr 2004 19:11:26 GMT, joe@invalid.address <joe@invalid.address> wrote:
>
>
> Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:
>
>
> This has come up enough that I've added the following to the FAQ under
> the date arithmetic section:
>
> h. Getting the number of seconds since the epoch
>
> GNU date has the %s format option which returns the epoch
> time. More portably, use awk
>
> awk 'BEGIN {srand();print srand()}'
>
> This works because srand() sets its seed value with the current
> epoch time if not given an argument. It also returns the
> previous seed value, so the second call gives the epoch time.
>
> Depending on scheduling, when the call is actually executed,
> etc, this might be off by a second.
>


When I think of the number of times that I've wished for a
a way to get the number of seconds since the epoch without using
GNU date....

But how do you find the number of seconds since the epoch for
a date other than the present, like Mar 6 1997?

AC

Jeremy Holdstadt

2004-04-26, 3:34 pm

Alan Connor wrote:
>
>
> On Sun, 25 Apr 2004 19:11:26 GMT, joe@invalid.address <joe@invalid.address> wrote:
>
> When I think of the number of times that I've wished for a
> a way to get the number of seconds since the epoch without using
> GNU date....
>
> But how do you find the number of seconds since the epoch for
> a date other than the present, like Mar 6 1997?
>
> AC
>


I'd like to know that too, although I think we need to add the hour and seconds
to it, don't you? Like Mar 6 1997 12:23 PM ?

I guess Charles Demas must be the local troll? Regardless, I've already
killfiled the jerkazoid.

Jeremy

--
I think, therefore I am. I think.
joe@invalid.address

2004-04-26, 4:35 pm

Jeremy Holdstadt <nospam@this.address> writes:

> I guess Charles Demas must be the local troll?


No

> Regardless, I've already killfiled the jerkazoid.


Your choice, but be aware that people here know that the real local
troll morphs his identity periodically. You're posting from earthlink
and sounding a lot like him, so you might want to reconsider your
posting style.

And no, your different User-Agent: line doesn't matter.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Jeremy Holdstadt

2004-04-26, 5:34 pm

joe@invalid.address wrote:
>
>
> Jeremy Holdstadt <nospam@this.address> writes:
>
>
> No
>
>
> Your choice, but be aware that people here know that the real local
> troll morphs his identity periodically. You're posting from earthlink
> and sounding a lot like him, so you might want to reconsider your
> posting style.
>


What have I stumbled into here? A trolls-nest? That Demas person posts
a downright nasty article in response to a reasonable question, and you
say not a word, and I get this for doing what any sane person would
do to someone like that?

Do you have any idea how many people use Earthlink, you nitwit?

> And no, your different User-Agent: line doesn't matter.
>


I'm at work, fool! I run Linux at home!

You won't mind if I killfile you too?

How could the "real local troll" be any worse than these two cretins?


Jeremy
--
I think, therefore I am. I think.

joe@invalid.address

2004-04-26, 5:34 pm

Jeremy Holdstadt <nospam@this.address> writes:

> You won't mind if I killfile you too?


Not at all, please do.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Alan Connor

2004-04-26, 5:34 pm

On Mon, 26 Apr 2004 20:46:45 GMT, Jeremy Holdstadt <nospam@this.address> wrote:
>
>
> joe@invalid.address wrote:
>
> What have I stumbled into here? A trolls-nest? That Demas person posts
> a downright nasty article in response to a reasonable question, and you
> say not a word, and I get this for doing what any sane person would
> do to someone like that?
>
> Do you have any idea how many people use Earthlink, you nitwit?
>
>
> I'm at work, fool! I run Linux at home!
>
> You won't mind if I killfile you too?
>
> How could the "real local troll" be any worse than these two cretins?
>
>
>


ROTFLMAO!

Hi Jeremy. I'm the "real local troll" that Joe Invalid is referring to.

What? You couldn't tell that from my posts? Whatta surprise.


Both he and Charles Dumbass have tried to push me around and gotten
their ears boxed, and like the over-ripe schoolyard bullies they
are, can't get over it.

I don't read Dumbass's articles anymore, but can well imagine the sort
of sophomoric crap he posted.

Sorry about this. Most of the people on this group are great, and there
are some real pros here.

Unlike Joe Invalid, who just plays the role and pastes from manpages or from the
archives.

And Dumbass, who thinks that Unix was written in Perl.

(you'll note that neither of them can answer our question :-)



Don't let them get you down.


AC

--
Pass-List -----> Block-List ----> Challenge-Response
The key to taking control of your mailbox.
Design Parameters: http://tinyurl.com/2t5kp
http://tinyurl.com/3c3ag Challenge-Response links -- http://tinyurl.com/yrfjb
Rich

2004-04-26, 5:34 pm



In whatever wisdom joe@invalid.address answered:
> Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:
>
>
>
>
> This has come up enough that I've added the following to the FAQ under
> the date arithmetic section:
>
> h. Getting the number of seconds since the epoch
>
> GNU date has the %s format option which returns the epoch
> time. More portably, use awk
>
> awk 'BEGIN {srand();print srand()}'


Interesting, this gives errors in Solaris 8.

% awk 'BEGIN {srand();print srand()}'
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1

But it works with nawk.

% nawk 'BEGIN {srand();print srand()}'
1083013284

One question remains. While I use epoch time to figure time differences,
it's not useful for figuring the date three weeks ago, or ahead, as
I know of no way to convert epoch time to calendar time. Is there
any way to convert epoch time to a calendar date?

Gnu date won't do it, although it will figure the date three weeks
from now. At least not for the version I have.

% gnu_date --v
date (coreutils) 4.5.4
Written by David MacKenzie.

It also works with the old gawk I have.

% gawk --v
GNU Awk 3.1.0
Copyright (C) 1989, 1991-2001 Free Software Foundation.

Nontheless, the awk (nawk for me) code's it's a neat trick.

Rich


> This works because srand() sets its seed value with the current
> epoch time if not given an argument. It also returns the
> previous seed value, so the second call gives the epoch time.
>
> Depending on scheduling, when the call is actually executed,
> etc, this might be off by a second.
>
> Another way is to use PERL if you have it.
>
> PERL -e 'print time,"\n"'
>
> Comments would be welcome before committing this.
>
> Joe


joe@invalid.address

2004-04-26, 5:34 pm

Alan Connor <zzzzzz@xxx.yyy> writes:

[...]

> ROTFLMAO!
>
> Hi Jeremy. I'm the "real local troll" that Joe Invalid is referring
> to.


You still haven't figured out that "invalid" is part of the fake
address, and not my last name? Here's a clue: the stuff after the '@'
character is part of the address, not the user name. Using your logic
'xxx' should be your last name.

I probably shouldn't have given into this moment of weakness ...

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Paul D. Smith

2004-04-26, 6:37 pm

%% Jeremy Holdstadt <nospam@this.address> writes:

jh> joe@invalid.address wrote:[vbcol=seagreen]

jh> What have I stumbled into here? A trolls-nest? That Demas person
jh> posts a downright nasty article in response to a reasonable
jh> question, and you say not a word, and I get this for doing what
jh> any sane person would do to someone like that?

jh> Do you have any idea how many people use Earthlink, you nitwit?
[vbcol=seagreen]

jh> I'm at work, fool! I run Linux at home!

jh> You won't mind if I killfile you too?

jh> How could the "real local troll" be any worse than these two cretins?

It's never a good idea to make snap judgements and start publicly
killfiling people immediately upon entering a group.

A newsgroup has a history and judging people based on a few seconds
excerpted from the middle of that history is not a reliable method for
discovering who the players are and what they know and do not know, and
whether they're worth listening to regardless of what they know (some
are, some aren't).


Read for a week or two and the group dynamics should be clear enough for
you to choose who's worth reading and who's not--sometimes you end up
deciding the entire group isn't worth reading . In the meantime, it's
wiser to avoid getting involved in long-running arguments.

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@nortelnetworks.com> HASMAT--HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.
Charles Demas

2004-04-26, 6:37 pm

In article <408D7AD9.3070806@somewhere.com>,
Rich <someone@somewhere.com> wrote:
>
>
>In whatever wisdom joe@invalid.address answered:
>
>Interesting, this gives errors in Solaris 8.
>
> % awk 'BEGIN {srand();print srand()}'
> awk: syntax error near line 1
> awk: illegal statement near line 1
> awk: syntax error near line 1
> awk: illegal statement near line 1
>
>But it works with nawk.


awk on Solaris is old awk and probably doesn't have the srand
function.


Chuck Demas

--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
demas@theworld.com | \___/ | http://world.std.com/~cpd
joe@invalid.address

2004-04-26, 6:37 pm

Rich <someone@somewhere.com> writes:

> In whatever wisdom joe@invalid.address answered:
>
> Interesting, this gives errors in Solaris 8.
>
> % awk 'BEGIN {srand();print srand()}'
> awk: syntax error near line 1
> awk: illegal statement near line 1
> awk: syntax error near line 1
> awk: illegal statement near line 1
>
> But it works with nawk.
>
> % nawk 'BEGIN {srand();print srand()}'
> 1083013284


Hmm, the Solaris 8 man page for awk doesn't even contain a description
of srand(). I'll have to point out that this can only be depended on
with POSIX forms of awk. Thanks.

> One question remains. While I use epoch time to figure time
> differences, it's not useful for figuring the date three weeks ago,
> or ahead, as I know of no way to convert epoch time to calendar
> time. Is there any way to convert epoch time to a calendar date?


I'm not sure, but the section "Abitrary date arithmetic" in the FAQ
might be of some use. If not, let us know why not and we can probably
add another section to cover what you want.

http://home.comcast.net/~j.p.h/cus-faq.html#G

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Peter J. Acklam

2004-04-26, 6:37 pm

Alan Connor <zzzzzz@xxx.yyy> wrote:

> But how do you find the number of seconds since the epoch for a
> date other than the present, like Mar 6 1997?


Some time ago I posted the pure ksh/bash/zsh scripts "gymdhms2use"
and "gymdhms2usec" which converts from Gregorian year, month, day,
hours, minutes, and seconds to UNIX seconds and back. You can
find them with Google.

I'll post them again if you like.

Peter

--
Peter J. Acklam - pjacklam@online.no - http://home.online.no/~pjacklam
Jeremy Holdstadt

2004-04-26, 6:37 pm

Paul D. Smith wrote:
>

[...]

>
> It's never a good idea to make snap judgements and start publicly
> killfiling people immediately upon entering a group.
>
> A newsgroup has a history and judging people based on a few seconds
> excerpted from the middle of that history is not a reliable method for
> discovering who the players are and what they know and do not know, and
> whether they're worth listening to regardless of what they know (some
> are, some aren't).
>
>
> Read for a week or two and the group dynamics should be clear enough for
> you to choose who's worth reading and who's not--sometimes you end up
> deciding the entire group isn't worth reading . In the meantime, it's
> wiser to avoid getting involved in long-running arguments.
>
> --
> -------------------------------------------------------------------------------
> Paul D. Smith <psmith@nortelnetworks.com> HASMAT--HA Software Mthds & Tools
> "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
> -------------------------------------------------------------------------------
> These are my opinions---Nortel Networks takes no responsibility for them.


Thank you Paul. That's very good advice. But I have looked back through Alan's
last 50 or so posts, and just don't see him as a troll of any kind. I see him
being hassled a bit, and striking back sometimes, but that isn't the same
thing.

People can change, and some do. Maybe he was a bad apple at one point, I don't
know or care. I am going to treat people as they are in the present, and both
of those guys behaved far worse than he did. Towards *me* too.

On the subject at hand, I've posted the question on comp.lang.awk, and if
I get something good will share it here.

Jeremy

--
I think, therefore I am. I think.
Peter J. Acklam

2004-04-26, 6:37 pm

joe@invalid.address wrote:

> "John W. Krahn" <krahnj@acm.org> writes:
>
>
> That's kind of cool, I have to admit. Still, I feel some
> responsibility to make the FAQ more or less understandable :-)


This has the best of both:

perl -le 'print time'

Peter

--
Peter J. Acklam - pjacklam@online.no - http://home.online.no/~pjacklam
Chris Thompson

2004-04-26, 7:38 pm

In article <408D7AD9.3070806@somewhere.com>,
Rich <someone@somewhere.com> wrote:
>
>
>In whatever wisdom joe@invalid.address answered:
>
>Interesting, this gives errors in Solaris 8.


Or in Solaris 9. And ever more shall be so, I suspect.

> % awk 'BEGIN {srand();print srand()}'
> awk: syntax error near line 1
> awk: illegal statement near line 1
> awk: syntax error near line 1
> awk: illegal statement near line 1
>
>But it works with nawk.


Or with /usr/xpg4/bin/awk.

> % nawk 'BEGIN {srand();print srand()}'
> 1083013284


Interestingly for nawk [but not /usr/xpg4/bin/awk] the first srand()
isn't necessary. It seems that nawk has already inititialised the
random number generator using the time.

[... snip snip ...][vbcol=seagreen]

As regards the arguments about short-but-obscure versions of this,
I think the sensible compromise is

perl -le 'print time'

-l is often useful in PERL 1-liners like this, so it makes sense to
use it here, to get newbies used to the idea.

Chris Thompson
Email: cet1 [at] cam.ac.uk
Alan Connor

2004-04-26, 7:38 pm

On 27 Apr 2004 00:42:40 +0200, Peter J. Acklam <pjacklam@online.no> wrote:
>
>
> Alan Connor <zzzzzz@xxx.yyy> wrote:
>
>
> Some time ago I posted the pure ksh/bash/zsh scripts "gymdhms2use"
> and "gymdhms2usec" which converts from Gregorian year, month, day,
> hours, minutes, and seconds to UNIX seconds and back. You can
> find them with Google.
>
> I'll post them again if you like.
>
> Peter
>


Would you, Peter? That would be GREAT!

I'd like to see them posted here again. (How did I miss them
the first time?)

Hopefully it will be included in the FAQ, (if you don't mind).

Seems like this should be a standard utility...

GPL?

AC

joe@invalid.address

2004-04-26, 11:34 pm

pjacklam@online.no (Peter J. Acklam) writes:

> Some time ago I posted the pure ksh/bash/zsh scripts "gymdhms2use"
> and "gymdhms2usec" which converts from Gregorian year, month, day,
> hours, minutes, and seconds to UNIX seconds and back. You can find
> them with Google.


http://groups.google.com/groups?q=g...nline.no&rnum=1

This was back in 2002, so I didn't catch it, but comments would be
welcome.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Geoff Clare

2004-04-27, 9:34 am

"joe" <joe@invalid.address> wrote, on Sun, 25 Apr 2004:

> This has come up enough that I've added the following to the FAQ under
> the date arithmetic section:
>
> h. Getting the number of seconds since the epoch
>
> GNU date has the %s format option which returns the epoch
> time. More portably, use awk
>
> awk 'BEGIN {srand();print srand()}'


This could produce output in floating point format (e.g. 1.08307e+09)
with some versions of awk. It would be better to put this in
the FAQ:

awk 'BEGIN {srand();printf "%d\n", srand()}'


--
Geoff Clare <nospam@gclare.org.uk>
joe@invalid.address

2004-04-27, 10:34 am

Geoff Clare <geoff@clare.See-My-Signature.invalid> writes:

> "joe" <joe@invalid.address> wrote, on Sun, 25 Apr 2004:
>
>
> This could produce output in floating point format (e.g. 1.08307e+09)
> with some versions of awk. It would be better to put this in
> the FAQ:
>
> awk 'BEGIN {srand();printf "%d\n", srand()}'


Thanks

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Rich

2004-04-27, 10:34 am



In infinite wisdom joe@invalid.address answered:
> Rich <someone@somewhere.com> writes:
>
>
>
>
> Hmm, the Solaris 8 man page for awk doesn't even contain a description
> of srand(). I'll have to point out that this can only be depended on
> with POSIX forms of awk. Thanks.


Interestingly, awk does not seem to have a version command, and 'what'
just gives the compile date.

>
> I'm not sure, but the section "Abitrary date arithmetic" in the FAQ
> might be of some use. If not, let us know why not and we can probably
> add another section to cover what you want.
>
> http://home.comcast.net/~j.p.h/cus-faq.html#G


As long as I have gnu date, I've no need to look for a conversion. One
rather awkward possibility might be to use mysql or your sql database,
which normally have many ways to handle date arithmetic.

One note, your section on email attachments is pretty good, but I found
a resource (and a neat sh program) that deserves note.

Sending files as email attachments
http://home.clara.net/dwotton/unix/mail_files.htm

Perhaps this is worth adding to the FAQ?

Rich

> Joe


Jeremy Holdstadt

2004-04-27, 12:35 pm

Jeremy Holdstadt wrote:

[...]

>
>
> On the subject at hand, I've posted the question on comp.lang.awk, and if
> I get something good will share it here.
>
> Jeremy
>
> --
> I think, therefore I am. I think.



This is what I got from comp.lang.awk


In article <OJcjc.11859$gH6.8943@newsread3.news.atl.earthlink.net>,
Jeremy Holdstadt <nospam@this.address> wrote:

% This command will return the number of seconds that have
% elapsed since the epoch:
%
% awk 'BEGIN {srand();print srand()}'

It will. It's not really the most straight-forward way of doing that,
though. For instance, there's a command which prints the current time
(called date), and it can be told what format to print it in:

date +%s

On my system, date can perform this conversion:

date -j +%s 198002121223

If you don't mind restricting yourself to gawk, a better (in the sense
that it's more straightforward and less computationally expensive) way
to get the current date is

awk 'BEGIN { print systime() }'

Unfortunately, there's no function which performs the conversion
you seek.
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com


Back to monitoring. I sure learn a lot here. Thanks to most everyone,
especially Peter J. Acklam for those really fine scripts.


Jeremy

--
I think, therefore I am. I think
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com