From owner-freebsd-questions@FreeBSD.ORG Fri Jun 8 01:24:48 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 D34BC1065672 for ; Fri, 8 Jun 2012 01:24:48 +0000 (UTC) (envelope-from racerx@makeworld.com) Received: from omr14.networksolutionsemail.com (omr14.networksolutionsemail.com [205.178.146.64]) by mx1.freebsd.org (Postfix) with ESMTP id 75DC98FC08 for ; Fri, 8 Jun 2012 01:24:48 +0000 (UTC) Received: from cm-omr3 (mail.networksolutionsemail.com [205.178.146.50]) by omr14.networksolutionsemail.com (8.13.8/8.13.8) with ESMTP id q581OgN9011480 for ; Thu, 7 Jun 2012 21:24:42 -0400 Authentication-Results: cm-omr3 smtp.user=racerx@makeworld.com; auth=pass (CRAM-MD5) X-Authenticated-UID: racerx@makeworld.com Received: from [50.44.138.106] ([50.44.138.106:53013] helo=[192.168.222.21]) by cm-omr3 (envelope-from ) (ecelerity 2.2.2.41 r(31179/31189)) with ESMTPA id 60/B3-14279-95451DF4; Thu, 07 Jun 2012 21:24:42 -0400 Message-ID: <4FD15461.6090109@makeworld.com> Date: Thu, 07 Jun 2012 20:24:49 -0500 From: Chris User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <4FD1360D.1060208@a1poweruser.com> In-Reply-To: X-Enigmail-Version: 1.4.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 01:24:48 -0000 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 <><