Re: find date of last boot

2012-06-08 Thread Matthew Seaman
On 08/06/2012 00:15, Fbsd8 wrote:
 dmesg command does not show date of last boot.
 
 Are there some other commands to find date of last boot?

% last reboot

will show the date of the last reboot if it is still in the current
/var/log/utx.log

Or at least it should: testing on my own system while writing this
failed to show the date of my last reboot.  Looks like you've stumbled
across a bug.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW





signature.asc
Description: OpenPGP digital signature


Re: find date of last boot

2012-06-08 Thread Matthew Seaman
On 08/06/2012 05:50, Randal L. Schwartz wrote:
 Sure, but the question was likely involving a stock system, so yes, your
 mileage may vary, but let's consider a solution that works for a default
 system.  last reboot isn't it.

It's not that.  'last reboot' seems to be broken at the moment, at least
on stable/9:

lucid-nonsense:~:% uname -a
FreeBSD lucid-nonsense.infracaninophile.co.uk 9.0-STABLE FreeBSD
9.0-STABLE #15 r236465: Sat Jun  2 23:14:59 BST 2012
r...@lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE
 amd64

I rebooted a few days ago:

lucid-nonsense:~:% uptime
 7:14AM  up 3 days,  8:18, 1 user, load averages: 0.03, 0.01, 0.01

And the utx.log file was last rotated over a week ago:

lucid-nonsense:~:% ls -la /var/log/utx*
-rw-r--r--  1 root  wheel394 Jun  7 17:51 /var/log/utx.lastlogin
-rw-r--r--  1 root  wheel  16841 Jun  8 07:06 /var/log/utx.log
-rw-r--r--  1 root  wheel  24878 May 31 22:41 /var/log/utx.log.0
-rw-r--r--  1 root  wheel  13741 Apr 30 08:50 /var/log/utx.log.1
-rw-r--r--  1 root  wheel  27886 Mar 31 22:52 /var/log/utx.log.2

but last(1) isn't coming up with the goods:

lucid-nonsense:~:% last reboot

wtmp begins Fri Jun  1 06:14:46 BST 2012

(nor does it work if I tell last to use the older utx.log files)

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW





signature.asc
Description: OpenPGP digital signature


Re: find date of last boot

2012-06-08 Thread Chris Knipe
 It's not that.  'last reboot' seems to be broken at the moment, at least
 on stable/9:

 but last(1) isn't coming up with the goods:

 lucid-nonsense:~:% last reboot

 wtmp begins Fri Jun  1 06:14:46 BST 2012

last reads from /var/log/wtmp - which more than likely got rotated
since your last reboot.


-- 

Regards,
Chris Knipe
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-08 Thread Matthew Seaman
On 08/06/2012 07:23, Chris Knipe wrote:
 It's not that.  'last reboot' seems to be broken at the moment, at least
 on stable/9:
 
 but last(1) isn't coming up with the goods:

 lucid-nonsense:~:% last reboot

 wtmp begins Fri Jun  1 06:14:46 BST 2012
 
 last reads from /var/log/wtmp - which more than likely got rotated
 since your last reboot.

No.  Please read more carefully.

last(1) used to use /var/log/wtmp, but not on 9.x or above, which uses
/var/log/utx.log -- a different binary format, but basically the same
idea as wtmp.

And, no: as I showed, that file was not rotated since my last reboot.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW





signature.asc
Description: OpenPGP digital signature


Re: find date of last boot

2012-06-08 Thread Matthew Seaman
On 08/06/2012 07:19, Matthew Seaman wrote:
 On 08/06/2012 05:50, Randal L. Schwartz wrote:
 Sure, but the question was likely involving a stock system, so yes, your
 mileage may vary, but let's consider a solution that works for a default
 system.  last reboot isn't it.
 
 It's not that.  'last reboot' seems to be broken at the moment, at least
 on stable/9:
 
 lucid-nonsense:~:% uname -a
 FreeBSD lucid-nonsense.infracaninophile.co.uk 9.0-STABLE FreeBSD
 9.0-STABLE #15 r236465: Sat Jun  2 23:14:59 BST 2012
 r...@lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE
  amd64
 
 I rebooted a few days ago:
 
 lucid-nonsense:~:% uptime
  7:14AM  up 3 days,  8:18, 1 user, load averages: 0.03, 0.01, 0.01
 
 And the utx.log file was last rotated over a week ago:
 
 lucid-nonsense:~:% ls -la /var/log/utx*
 -rw-r--r--  1 root  wheel394 Jun  7 17:51 /var/log/utx.lastlogin
 -rw-r--r--  1 root  wheel  16841 Jun  8 07:06 /var/log/utx.log
 -rw-r--r--  1 root  wheel  24878 May 31 22:41 /var/log/utx.log.0
 -rw-r--r--  1 root  wheel  13741 Apr 30 08:50 /var/log/utx.log.1
 -rw-r--r--  1 root  wheel  27886 Mar 31 22:52 /var/log/utx.log.2
 
 but last(1) isn't coming up with the goods:
 
 lucid-nonsense:~:% last reboot
 
 wtmp begins Fri Jun  1 06:14:46 BST 2012
 
 (nor does it work if I tell last to use the older utx.log files)

Having investigated, the problem appears to be that wtmp used to use the
literal string 'reboot' in the username field of its records, while in
struct utmpx, that field is left blank but the record type field
indicates if this is the time the system shutdown or rebooted.

The attached patch fixes the problem for me.  Or see

http://www.freebsd.org/cgi/query-pr.cgi?pr=168844

lucid-nonsense:~:% /usr/obj/usr/src/usr.bin/last/last reboot
boot time  Mon Jun  4 22:58
shutdown time  Mon Jun  4 22:54
boot time  Sun Jun  3 09:43
shutdown time  Sun Jun  3 09:39

wtmp begins Fri Jun  1 06:14:46 BST 2012

In passing, apparently it seems that creating a user with a username of
'reboot' is probably not recommended.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW


Index: usr.bin/last/last.c
===
--- usr.bin/last/last.c (revision 236465)
+++ usr.bin/last/last.c (working copy)
@@ -64,6 +64,7 @@
 
 typedef struct arg {
char*name;  /* argument */
+#defineREBOOT_TYPE -1
 #defineHOST_TYPE   -2
 #defineTTY_TYPE-3
 #defineUSER_TYPE   -4
@@ -180,6 +181,8 @@
if (argc) {
setlinebuf(stdout);
for (argv += optind; *argv; ++argv) {
+   if (strcmp(*argv, reboot) == 0)
+   addarg(REBOOT_TYPE, *argv);
 #defineCOMPATIBILITY
 #ifdef COMPATIBILITY
/* code to allow last p5 to work */
@@ -391,6 +394,11 @@
 
for (step = arglist; step; step = step-next)
switch(step-type) {
+   case REBOOT_TYPE:
+   if (bp-ut_type == BOOT_TIME ||
+   bp-ut_type == SHUTDOWN_TIME)
+   return (YES);
+   break;
case HOST_TYPE:
if (!strcasecmp(step-name, bp-ut_host))
return (YES);


signature.asc
Description: OpenPGP digital signature


Re: find date of last boot

2012-06-08 Thread Jerry
On Fri, 08 Jun 2012 12:08:20 +0100
Matthew Seaman articulated:

In passing, apparently it seems that creating a user with a username of
'reboot' is probably not recommended.

That would seem like a good idea. Interestingly enough, I had a friend
who had a password: PassWord that he used as a joke. On day he
tried it on an internet site for a throw away account he was creating
and the site rejected it claiming it was not a valid password. Perhaps
FreeBSD could have some sort of validation in place to refuse to accept
certain user-IDs such as reboot.

-- 
Jerry ♔

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the Reply-To header.
__



signature.asc
Description: PGP signature


find date of last boot

2012-06-07 Thread Fbsd8

dmesg command does not show date of last boot.

Are there some other commands to find date of last boot?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris Hill

On Thu, 7 Jun 2012, Fbsd8 wrote:


dmesg command does not show date of last boot.

Are there some other commands to find date of last boot?


Perhaps somehow subtract `uptime` from today's date?

--
Chris Hill   ch...@monochrome.org
** [ Busy Expunging / ]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Bill Yuan
If you store the time in a file as log everytime when it boots up,
then that means you can have more then now -  uptime

On Fri, Jun 8, 2012 at 7:20 AM, Chris Hill ch...@monochrome.org wrote:

 On Thu, 7 Jun 2012, Fbsd8 wrote:

 dmesg command does not show date of last boot.

 Are there some other commands to find date of last boot?


 Perhaps somehow subtract `uptime` from today's date?

 --
 Chris Hill   ch...@monochrome.org
 ** [ Busy Expunging / ]

 __**_
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/**mailman/listinfo/freebsd-**questionshttp://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-**
 unsubscr...@freebsd.org freebsd-questions-unsubscr...@freebsd.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Polytropon
On Thu, 07 Jun 2012 19:15:25 -0400, Fbsd8 wrote:
 dmesg command does not show date of last boot.
 
 Are there some other commands to find date of last boot?

Check the lines in /var/log/messages. Unless you're not
experiencing a newsyslog message (new log file started),
the kernel: Copyright (c) 1992-2011 The FreeBSD Project.
string (first line of typical dmesg, check for your particular
OS version!) indicates when the system was booted. But
note that the date format is not the common sortable
kind of `date +%d.%m.%Y`.

Another idea (as already mentioned) is to subtract `uptime`
from current `date`. :-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris
On 6/7/2012 6:31 PM, Bill Yuan wrote:
 If you store the time in a file as log everytime when it boots up,
 then that means you can have more then now -  uptime
 
 On Fri, Jun 8, 2012 at 7:20 AM, Chris Hill ch...@monochrome.org wrote:
 
 On Thu, 7 Jun 2012, Fbsd8 wrote:

 dmesg command does not show date of last boot.

 Are there some other commands to find date of last boot?


 Perhaps somehow subtract `uptime` from today's date?

 --
 Chris Hill   ch...@monochrome.org
 ** [ Busy Expunging / ]

 __**_
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/**mailman/listinfo/freebsd-**questionshttp://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-**
 unsubscr...@freebsd.org freebsd-questions-unsubscr...@freebsd.org

 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
 
 
 


Try the command,  last
maybe that will give you some info that you are looking for.


-- 
Keep well,

Chris
 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Fish Kungfu
Try:  who -b

Cheers...Fish


07.06.2012, 18:31, Bill Yuan byc...@gmail.com:
 If you store the time in a file as log everytime when it boots up,
 then that means you can have more then now -  uptime

 On Fri, Jun 8, 2012 at 7:20 AM, Chris Hill ch...@monochrome.org wrote:

  On Thu, 7 Jun 2012, Fbsd8 wrote:

  dmesg command does not show date of last boot.
  Are there some other commands to find date of last boot?
  Perhaps somehow subtract `uptime` from today's date?

  --
  Chris Hill   ch...@monochrome.org
  ** [ Busy Expunging / ]

  __**_
  freebsd-questions@freebsd.org mailing list
  http://lists.freebsd.org/**mailman/listinfo/freebsd-**questionshttp://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to freebsd-questions-**
  unsubscr...@freebsd.org freebsd-questions-unsubscr...@freebsd.org

 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Robert Bonomi
 From owner-freebsd-questi...@freebsd.org  Thu Jun  7 18:16:50 2012
 Date: Thu, 07 Jun 2012 19:15:25 -0400
 From: Fbsd8 fb...@a1poweruser.com
 To: FreeBSD Questions freebsd-questions@freebsd.org
 Subject: find date of last boot

 dmesg command does not show date of last boot.

 Are there some other commands to find date of last boot?

'man uptime'

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Karl Vogel
 On Thu, 07 Jun 2012 19:15:25 -0400, 
 Fbsd8 fb...@a1poweruser.com said:

F dmesg command does not show date of last boot.  Are there some other
F commands to find date of last boot?

   Try last reboot.

-- 
Karl Vogel  I don't speak for the USAF or my company

He is not only dull himself; he is the cause of dullness in others.
--Samuel Johnson
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Doug Hardie

On 7 June 2012, at 16:33, Polytropon wrote:

 On Thu, 07 Jun 2012 19:15:25 -0400, Fbsd8 wrote:
 dmesg command does not show date of last boot.
 
 Are there some other commands to find date of last boot?
 
 Check the lines in /var/log/messages. Unless you're not
 experiencing a newsyslog message (new log file started),
 the kernel: Copyright (c) 1992-2011 The FreeBSD Project.
 string (first line of typical dmesg, check for your particular
 OS version!) indicates when the system was booted. But
 note that the date format is not the common sortable
 kind of `date +%d.%m.%Y`.
 
 Another idea (as already mentioned) is to subtract `uptime`
 from current `date`. :-


Check the timestamp on /var/run/dmesg.boot  That is only written to when the 
system boots.___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chuck Swiger
On Jun 7, 2012, at 4:15 PM, Fbsd8 wrote:
 dmesg command does not show date of last boot.
 
 Are there some other commands to find date of last boot?

Try last | grep reboot.  

Regards,
-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris Hill

On Thu, 7 Jun 2012, Fbsd8 wrote:


dmesg command does not show date of last boot.

Are there some other commands to find date of last boot?


That was fun. Google helped me with this; the crappy skillz are all 
mine.


 --- cut here ---
#!/bin/sh
#
# Find date of last boot
#
DAYS_UP=`uptime | awk '{print $3}'`
SEC_UP=`echo ${DAYS_UP} * 86400 | bc`
DATE=`date`
EPOCH_DATE=`date -j -f %a %b %d %T %Z %Y ${DATE} +%s`
BOOT_SEC=`echo ${EPOCH_DATE} - ${SEC_UP} | bc`
BOOT_DATE=`gawk -v duh=${BOOT_SEC} 'BEGIN{print strftime(%Y-%m-%d,duh)}'`
echo Last boot on ${BOOT_DATE}
 --- cut here ---

Example from this machine:
$ ./boot_date.sh
Last boot on 2010-12-26
$

Enjoy.

--
Chris Hill   ch...@monochrome.org
** [ Busy Expunging / ]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris
On 6/7/2012 8:14 PM, Chris Hill wrote:
 On Thu, 7 Jun 2012, Fbsd8 wrote:
 
 dmesg command does not show date of last boot.

 Are there some other commands to find date of last boot?
 
 That was fun. Google helped me with this; the crappy skillz are all mine.
 
  --- cut here ---
 #!/bin/sh
 #
 # Find date of last boot
 #
 DAYS_UP=`uptime | awk '{print $3}'`
 SEC_UP=`echo ${DAYS_UP} * 86400 | bc`
 DATE=`date`
 EPOCH_DATE=`date -j -f %a %b %d %T %Z %Y ${DATE} +%s`
 BOOT_SEC=`echo ${EPOCH_DATE} - ${SEC_UP} | bc`
 BOOT_DATE=`gawk -v duh=${BOOT_SEC} 'BEGIN{print strftime(%Y-%m-%d,duh)}'`
 echo Last boot on ${BOOT_DATE}
  --- cut here ---
 
 Example from this machine:
 $ ./boot_date.sh
 Last boot on 2010-12-26
 $
 
 Enjoy.
 

Why create something that is already built in?
As I mentioned previously, the last command lists when the system was
rebooted.

-- 
Keep well,

Chris
 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris Hill

On Thu, 7 Jun 2012, Chris wrote:


On 6/7/2012 8:14 PM, Chris Hill wrote:

On Thu, 7 Jun 2012, Fbsd8 wrote:


dmesg command does not show date of last boot.

Are there some other commands to find date of last boot?


That was fun. Google helped me with this; the crappy skillz are all mine.


-snip-


Why create something that is already built in?


Because I learned something by doing it.

As I mentioned previously, the last command lists when the system was 
rebooted.


I'm not sure it does:

$ last reboot
wtmp begins Fri Jun  1 08:31:38 EDT 2012
$ uptime
 9:30PM  up 529 days,  8:25, 4 users, load averages: 0.02, 0.18, 0.17

...and even so, would it show a cold boot, or only a reboot?

I'll credit Doug Hardie with the best solution:
$ ls -l /var/run/dmesg.boot
-rw-r--r--  1 root  wheel  7248 Dec 26  2010 /var/run/dmesg.boot


Keep well,


You too.

--
Chris Hill   ch...@monochrome.org
** [ Busy Expunging / ]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Randal L. Schwartz
 Chris == Chris  rac...@makeworld.com writes:

Chris Why create something that is already built in?
Chris As I mentioned previously, the last command lists when the system was
Chris rebooted.

You must reboot a lot.  My last log goes back only to the first of the
month, and my uptime is 16 days right now, so I can't see the most
recent reboot with last.

YMMV, I guess.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chris
On 6/7/2012 8:32 PM, Randal L. Schwartz wrote:
 Chris == Chris  rac...@makeworld.com writes:
 
 Chris Why create something that is already built in?
 Chris As I mentioned previously, the last command lists when the system was
 Chris rebooted.
 
 You must reboot a lot.  My last log goes back only to the first of the
 month, and my uptime is 16 days right now, so I can't see the most
 recent reboot with last.
 
 YMMV, I guess.
 

Good point, I didn't take into account the command goes about a month
back. I run FBSD in a vbox, and its only console anyways.

I run Debian by default but in any event, there are many reasons for
reboots and for me (typically) I see about 4 reboots a month mostly due
to patching and sec-fixes.

So indeed, YMMV is correct.

My fault for the assumption that folks boot more often than not.

-- 
Keep well,

Chris
 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Robert Bonomi
 From owner-freebsd-questi...@freebsd.org  Thu Jun  7 20:26:46 2012
 Date: Thu, 07 Jun 2012 20:24:49 -0500
 From: Chris rac...@makeworld.com
 To: freebsd-questions@freebsd.org
 Subject: Re: find date of last boot

 On 6/7/2012 8:14 PM, Chris Hill wrote:
  On Thu, 7 Jun 2012, Fbsd8 wrote:
  
  dmesg command does not show date of last boot.
 
  Are there some other commands to find date of last boot?
  
  That was fun. Google helped me with this; the crappy skillz are all mine.
  
   --- cut here ---
  #!/bin/sh
  #
  # Find date of last boot
  #
  DAYS_UP=`uptime | awk '{print $3}'`
  SEC_UP=`echo ${DAYS_UP} * 86400 | bc`
  DATE=`date`
  EPOCH_DATE=`date -j -f %a %b %d %T %Z %Y ${DATE} +%s`
  BOOT_SEC=`echo ${EPOCH_DATE} - ${SEC_UP} | bc`
  BOOT_DATE=`gawk -v duh=${BOOT_SEC} 'BEGIN{print strftime(%Y-%m-%d,duh)}'`
  echo Last boot on ${BOOT_DATE}
   --- cut here ---
  
  Example from this machine:
  $ ./boot_date.sh
  Last boot on 2010-12-26
  $
  
  Enjoy.
  

 Why create something that is already built in?
 As I mentioned previously, the last command lists when the system was
 rebooted.

Probably, because last does *not* reliably do so.  grin

To wit:
 $ date
 Thu Jun  7 20:59:44 CDT 2012
 $ uptime
 8:58PM  up 8 days, 22:30, 1 user, load averages: 0.07, 0.03, 0.01
 $ last reboot
 wtmp begins Tue Jun  5 17:00:58 CDT 2012
 $

'wtmp' has been rotated twice since the system was booted.



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Polytropon
On Thu, 7 Jun 2012 21:02:57 -0500 (CDT), Robert Bonomi wrote:
  From owner-freebsd-questi...@freebsd.org  Thu Jun  7 20:26:46 2012
  Date: Thu, 07 Jun 2012 20:24:49 -0500
  From: Chris rac...@makeworld.com
  To: freebsd-questions@freebsd.org
  Subject: Re: find date of last boot
 
  On 6/7/2012 8:14 PM, Chris Hill wrote:
  Why create something that is already built in?
  As I mentioned previously, the last command lists when the system was
  rebooted.
 
 Probably, because last does *not* reliably do so.  grin
 
 To wit:
  $ date
  Thu Jun  7 20:59:44 CDT 2012
  $ uptime
  8:58PM  up 8 days, 22:30, 1 user, load averages: 0.07, 0.03, 0.01
  $ last reboot
  wtmp begins Tue Jun  5 17:00:58 CDT 2012
  $
 
 'wtmp' has been rotated twice since the system was booted.

Maybe introducing something along the /etc/rc execution?
An /etc/rc.local entry like

/bin/date +%Y-%m-%d %H:%M:%S  /var/log/thisboot.log

and then just look at the file. Requires at least one reboot
to take effect. :-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Michael Sierchio
On Thu, Jun 7, 2012 at 7:34 PM, Polytropon free...@edvax.de wrote:

 Maybe introducing something along the /etc/rc execution?
 An /etc/rc.local entry like

        /bin/date +%Y-%m-%d %H:%M:%S  /var/log/thisboot.log

 and then just look at the file. Requires at least one reboot
 to take effect. :-)


You could just put the following in /etc/rc.local

date

and it would be retained in /var/run/dmesg.boot
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Karl Vogel
 On Thu, 7 Jun 2012 21:35:19 -0400 (EDT), 
 Chris Hill ch...@monochrome.org said:

C $ ls -l /var/run/dmesg.boot
C -rw-r--r-- 1 root wheel 7248 Dec 26 2010 /var/run/dmesg.boot

   For the sake of completeness:

   me% stat -f %Sm /var/run/dmesg.boot
   Jan 10 14:56:45 2012

   me% ls -l -D '%d-%b-%Y %T' /var/run/dmesg.boot
   -rw-r--r--  1 root  wheel  6319 10-Jan-2012 14:56:45 /var/run/dmesg.boot

-- 
Karl Vogel  I don't speak for the USAF or my company

Dirt and grease under the fingernails is a social no-no, as they tend to
detract from a woman's jewelry and alter the taste of finger foods.
   --Martha Stewart's hygiene tips for Rednecks
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Chuck Swiger
On Jun 7, 2012, at 6:32 PM, Randal L. Schwartz wrote:
 You must reboot a lot.  My last log goes back only to the first of the
 month, and my uptime is 16 days right now, so I can't see the most
 recent reboot with last.

FreeBSD aggressively rotates the utmp/wtmp databases; most other platforms
leave it in place until the sysadmin decides to rotate it per local policy.

Tweaking the monthly? periodic entries would change this, I'd imagine

Regards,
-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Carl Johnson
Fbsd8 fb...@a1poweruser.com writes:

 dmesg command does not show date of last boot.

 Are there some other commands to find date of last boot?

In addition to the other responses:

sysctl kern.boottime

-- 
Carl Johnsonca...@peak.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Randal L. Schwartz
 Chris == Chris Hill ch...@monochrome.org writes:

Chris I'll credit Doug Hardie with the best solution:
Chris $ ls -l /var/run/dmesg.boot
Chris -rw-r--r--  1 root  wheel  7248 Dec 26  2010 /var/run/dmesg.boot

Ouch!  There've been some security patches since then.  Are you sure you
want to tell someone that a machine has been running for over 18 months?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: find date of last boot

2012-06-07 Thread Randal L. Schwartz
 Chuck == Chuck Swiger cswi...@mac.com writes:

Chuck FreeBSD aggressively rotates the utmp/wtmp databases; most other
Chuck platforms leave it in place until the sysadmin decides to rotate
Chuck it per local policy.

Chuck Tweaking the monthly? periodic entries would change this, I'd
Chuck imagine

Sure, but the question was likely involving a stock system, so yes, your
mileage may vary, but let's consider a solution that works for a default
system.  last reboot isn't it.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org