From owner-freebsd-questions@FreeBSD.ORG Fri Jun 8 02:02:28 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 894F71065670 for ; Fri, 8 Jun 2012 02:02:28 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 0948C8FC12 for ; Fri, 8 Jun 2012 02:02:27 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id q5822vVd060619; Thu, 7 Jun 2012 21:02:57 -0500 (CDT) Date: Thu, 7 Jun 2012 21:02:57 -0500 (CDT) From: Robert Bonomi Message-Id: <201206080202.q5822vVd060619@mail.r-bonomi.com> To: freebsd-questions@freebsd.org, racerx@makeworld.com In-Reply-To: <4FD15461.6090109@makeworld.com> Cc: Subject: Re: find date of last boot X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jun 2012 02:02:28 -0000 > From owner-freebsd-questions@freebsd.org Thu Jun 7 20:26:46 2012 > Date: Thu, 07 Jun 2012 20:24:49 -0500 > From: Chris > 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. 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.