public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Finding either boot time or login time
@ 2009-01-30 15:33 Ronald Fischer
  2009-01-30 15:58 ` Eric Blake
  0 siblings, 1 reply; 12+ messages in thread
From: Ronald Fischer @ 2009-01-30 15:33 UTC (permalink / raw)
  To: cygwin

I'm a bit desperate. I'm looking for a way to find EITHER the time the system 
was booted, OR the time the last user had logged in, OR the time I had logged 
in (of course it would be great if I could find all of it, but one of this 
would already be sufficient).

From a past posting to this issue, I got the advice to use the 'last' command, 
but issuing, for instance,

  last

I only get 

  wtmp begins Thu Jan 29 09:22:40 2009

which is the time wtmp has been created (but there was at least one shutdown and
startup after this - why doesn't it show up in wtmp?).

Then I thought I could get this information by sysctl -a, but had to learn that 
this is not implemented.

Any other idea what I could try?

Ronald







--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 15:33 Finding either boot time or login time Ronald Fischer
@ 2009-01-30 15:58 ` Eric Blake
  2009-01-30 15:58   ` Ronald Fischer
  0 siblings, 1 reply; 12+ messages in thread
From: Eric Blake @ 2009-01-30 15:58 UTC (permalink / raw)
  To: cygwin, fischerr.external

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Ronald Fischer on 1/30/2009 6:02 AM:
> I'm a bit desperate. I'm looking for a way to find EITHER the time the system 
> was booted, OR the time the last user had logged in, OR the time I had logged 
> in (of course it would be great if I could find all of it, but one of this 
> would already be sufficient).

man uptime
Part of the procps package.

(although I've seen uptime count double on a dual core; where it
attributes 2 hours of uptime after only 1 hour of power)

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmC+3cACgkQ84KuGfSFAYDTswCfTOsapoZTr5kNIpgNYWWQs1XB
/14AoMoUDv7OFucXA757RiD+W4HHM9Wx
=n/lV
-----END PGP SIGNATURE-----

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 15:58 ` Eric Blake
@ 2009-01-30 15:58   ` Ronald Fischer
  2009-01-30 16:43     ` Fabian Cenedese
  2009-01-30 22:08     ` Brian Mathis
  0 siblings, 2 replies; 12+ messages in thread
From: Ronald Fischer @ 2009-01-30 15:58 UTC (permalink / raw)
  To: cygwin

Eric Blake <ebb9 <at> byu.net> writes:
> man uptime

I have thought of uptime, but this requires doing date calculation (I have to
subtract the uptime from the current time), which I wanted to avoid; plus I
wanted to have it reproducible (i.e. if I calculate the "startup time" twice
in succession, I wanted to get the same result - using the uptime calculation
might well give differences of, say, one, in rare cases 2, seconds for the 
startup time on repeated calculations.

But it seems there is no alternative. I had not expected that Windows would
not log such events, like starting up or having some user logged in...

Ronald


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 15:58   ` Ronald Fischer
@ 2009-01-30 16:43     ` Fabian Cenedese
  2009-01-30 17:02       ` Mark J. Reed
  2009-01-30 22:08     ` Brian Mathis
  1 sibling, 1 reply; 12+ messages in thread
From: Fabian Cenedese @ 2009-01-30 16:43 UTC (permalink / raw)
  To: cygwin


>But it seems there is no alternative. I had not expected that Windows would
>not log such events, like starting up or having some user logged in...

Windows does log such events in the system protocol/event log :)
But I don't know if you can get this info from cygwin...

bye  Fabi


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 16:43     ` Fabian Cenedese
@ 2009-01-30 17:02       ` Mark J. Reed
  2009-02-02 14:11         ` Ronald Fischer
  0 siblings, 1 reply; 12+ messages in thread
From: Mark J. Reed @ 2009-01-30 17:02 UTC (permalink / raw)
  To: cygwin

One-liner to display the boot time:

$ perl -lane 'print ~~localtime(time-$F[0])' /proc/uptime

Or format it however you want, e.g. for ISO8601:

$ perl -MPOSIX -lane 'print strftime("%FT%T", localtime(time-$F[0]))'
/proc/uptime

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 15:58   ` Ronald Fischer
  2009-01-30 16:43     ` Fabian Cenedese
@ 2009-01-30 22:08     ` Brian Mathis
  2009-01-30 22:45       ` Owen Rees
  1 sibling, 1 reply; 12+ messages in thread
From: Brian Mathis @ 2009-01-30 22:08 UTC (permalink / raw)
  To: cygwin

On Fri, Jan 30, 2009 at 10:33 AM, Ronald Fischer
<fischerr.external@infineon.com> wrote:
> Eric Blake <ebb9 <at> byu.net> writes:
>> man uptime
>
> I have thought of uptime, but this requires doing date calculation (I have to
> subtract the uptime from the current time), which I wanted to avoid; plus I
> wanted to have it reproducible (i.e. if I calculate the "startup time" twice
> in succession, I wanted to get the same result - using the uptime calculation
> might well give differences of, say, one, in rare cases 2, seconds for the
> startup time on repeated calculations.
>
> But it seems there is no alternative. I had not expected that Windows would
> not log such events, like starting up or having some user logged in...
>
> Ronald

This information is available in windows by using one of two commands:
    net stats srv
or
    systeminfo

In both cases, you will need to grep (if calling from cygwin) or use
the windows "find" command (equivalent of grep), to isolate just the 1
line.

I've noticed that, on Vista, "net stats srv" always seems to return
1980, while systeminfo returns the correct result.

If that doesn't work for you, I'm sure there are other ways to do it.
You might need to write some vbs and query WMI to get the uptime
(http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0907.mspx)
 Or you can install the "uptime" tool from Microsoft
(http://support.microsoft.com/kb/232243)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 22:08     ` Brian Mathis
@ 2009-01-30 22:45       ` Owen Rees
  0 siblings, 0 replies; 12+ messages in thread
From: Owen Rees @ 2009-01-30 22:45 UTC (permalink / raw)
  To: cygwin

--On 30 January 2009 10:58 -0500 Brian Mathis wrote:

> I've noticed that, on Vista, "net stats srv" always seems to return
> 1980, while systeminfo returns the correct result.

On this Vista system right now "net stats srv" says:

  Statistics since 27/01/2009 16:04:50

systeminfo says

  System Boot Time:          29/01/2009, 12:13:49

There is an event in the event log:

Log Name:      System
Source:        EventLog
Date:          27/01/2009 16:04:44
Event ID:      6013
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:
Description:
The system uptime is 39 seconds.

There is nothing in the event log near 29/01/2009, 12:13:49 that suggests a 
reboot happened then, and I don't think I rebooted then and the latest 
USER32/1074 "Shutdown Type: restart" was at 27/01/2009 14:44:39.

A later event says:

Date:          30/01/2009 12:00:59
The system uptime is 85630 seconds.

Which is consistent with the 29/01/2009, 12:13:49 time and so almost 
certainly wrong.

This is a dual core laptop that has been in hibernation since booting so 
make what you will of what the numbers say. If Windows does not have a way 
to report last boot time accurately then there is not really anything 
cygwin can do to get around that.

-- 
Owen Rees; speaking personally, and not on behalf of HP.
========================================================
Hewlett-Packard Limited.   Registered No: 690597 England
Registered Office:  Cain Road, Bracknell, Berks RG12 1HN


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-01-30 17:02       ` Mark J. Reed
@ 2009-02-02 14:11         ` Ronald Fischer
  2009-02-02 14:34           ` Jerry D. Hedden
  0 siblings, 1 reply; 12+ messages in thread
From: Ronald Fischer @ 2009-02-02 14:11 UTC (permalink / raw)
  To: cygwin

Mark J. Reed <markjreed <at> gmail.com> writes:

> One-liner to display the boot time:
> 
> $ perl -lane 'print ~~localtime(time-$F[0])' /proc/uptime

Thanks a lot! This is great!

Would you mind explaining the ~~ trick? localtime returns a list, so 
I would have concluded that applyiing ~ to this list would force it
into scalar context, so it would bitwise negate the number of elements
in the list. But this is obviously not done, because just by 
trying out your code, I see that it works.

Ronald



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-02-02 14:11         ` Ronald Fischer
@ 2009-02-02 14:34           ` Jerry D. Hedden
  2009-02-02 20:28             ` Mark J. Reed
  0 siblings, 1 reply; 12+ messages in thread
From: Jerry D. Hedden @ 2009-02-02 14:34 UTC (permalink / raw)
  To: cygwin

Mark J. Reed writes:
> One-liner to display the boot time:
> $ perl -lane 'print ~~localtime(time-$F[0])' /proc/uptime

Ronald Fischer wrote:
> Would you mind explaining the ~~ trick?

Clever tricks are interesting, but definitely are an obfuscation.
This makes things more plain:

perl -lane 'print(scalar(localtime(time() - int($F[0]))))' /proc/uptime

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Finding either boot time or login time
  2009-02-02 14:34           ` Jerry D. Hedden
@ 2009-02-02 20:28             ` Mark J. Reed
  0 siblings, 0 replies; 12+ messages in thread
From: Mark J. Reed @ 2009-02-02 20:28 UTC (permalink / raw)
  To: cygwin

On Mon, Feb 2, 2009 at 9:11 AM, Ronald Fischer wrote:
> Would you mind explaining the ~~ trick?

Not at all, but I'll do so offlist.  Perl-fu is not on-topic for Cygwin.


On Mon, Feb 2, 2009 at 9:34 AM, Jerry D. Hedden wrote:
> Clever tricks are interesting, but definitely are an obfuscation.

It's a one-liner; the goal is compactness/expressiveness, not
intentional obfuscation.  Sure, in a standalone script (or larger
system) I would have used scalar() instead of ~~.   I also would have
explicitly opened, read, and split the contents of /proc/uptime
instead of using the -a and -n options, and explicitly terminated the
output string with "\n" instead of using the -l option.  In other
words, ~~ is a common Perl idiom, whose use is no more obfuscating
than that of those command-line options.   Different methods for
different goals.


On Mon, Feb 2, 2009 at 11:54 AM, Cooper, Karl (US SSA) wrote:
>  I did try both of these one-liners on my
> Cygwin 1.7 setup, and the output differs (by one second).  I thought
> that was interesting.

Rounding difference.  Besides replacing my ~~ with scalar(), Jerry
added an int() call to truncate the value read from /proc/uptime - and
that change was more than cosmetic.  Since the return value of time()
is only accurate to the nearest integer, my script would return
different values depending on how far into the current second you were
when running it; Jerry's should behave more consistently.   Another
option is to correct in the other direction by using the Time::HiRes
module to cause the return value of time() to have millisecond
accuracy:

$ perl -MTime::HiRes=time -lane 'print ~~localtime(time - $F[0])' /proc/uptime

But it seems silly to worry about a one-second error on a call that is
apparently subject to much larger error due to the effect of
hibernation. :)

-- 
Mark J. Reed <markjreed@gmail.com>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: Finding either boot time or login time
  2009-02-02 16:54 Cooper, Karl (US SSA)
@ 2009-02-02 17:37 ` Owen Rees
  0 siblings, 0 replies; 12+ messages in thread
From: Owen Rees @ 2009-02-02 17:37 UTC (permalink / raw)
  To: cygwin

--On 02 February 2009 11:54 -0500 Cooper, Karl \(US SSA\) wrote:

> I don't know perl, but I did try both of these one-liners on my
> Cygwin 1.7 setup, and the output differs (by one second).  I thought
> that was interesting.

I get a one second difference between the two formulae as well (due to the 
use of 'int' in one but not the other) but that is insignificant compared 
to the 1 hour and 43 minutes by which both are wrong (and that is since 
rebooting at 08:57 this morning).

As far as I can tell, uptime does not include time spent in hibernation (or 
suspend/sleep probably).

A little web searching suggests that not counting sleep time is probably 
consistent with recent Linux behaviour.

I also noticed that the Windows Vista 'systeminfo' command gives the same 
wrong answer for "System Boot Time".

-- 
Owen Rees; speaking personally, and not on behalf of HP.
========================================================
Hewlett-Packard Limited.   Registered No: 690597 England
Registered Office:  Cain Road, Bracknell, Berks RG12 1HN


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: Finding either boot time or login time
@ 2009-02-02 16:54 Cooper, Karl (US SSA)
  2009-02-02 17:37 ` Owen Rees
  0 siblings, 1 reply; 12+ messages in thread
From: Cooper, Karl (US SSA) @ 2009-02-02 16:54 UTC (permalink / raw)
  To: Jerry D. Hedden, cygwin

> Mark J. Reed writes:
>> One-liner to display the boot time:
>> $ perl -lane 'print ~~localtime(time-$F[0])' /proc/uptime
> 
> Ronald Fischer wrote:
>> Would you mind explaining the ~~ trick?
> 
> Clever tricks are interesting, but definitely are an obfuscation.
> This makes things more plain:
> 
> perl -lane 'print(scalar(localtime(time() - int($F[0]))))'
> /proc/uptime 
I don't know perl, but I did try both of these one-liners on my
Cygwin 1.7 setup, and the output differs (by one second).  I thought
that was interesting.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-02-02 20:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-30 15:33 Finding either boot time or login time Ronald Fischer
2009-01-30 15:58 ` Eric Blake
2009-01-30 15:58   ` Ronald Fischer
2009-01-30 16:43     ` Fabian Cenedese
2009-01-30 17:02       ` Mark J. Reed
2009-02-02 14:11         ` Ronald Fischer
2009-02-02 14:34           ` Jerry D. Hedden
2009-02-02 20:28             ` Mark J. Reed
2009-01-30 22:08     ` Brian Mathis
2009-01-30 22:45       ` Owen Rees
2009-02-02 16:54 Cooper, Karl (US SSA)
2009-02-02 17:37 ` Owen Rees

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).