From owner-freebsd-questions@FreeBSD.ORG Fri Jun 8 01:14:13 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 426CC106566C for ; Fri, 8 Jun 2012 01:14:13 +0000 (UTC) (envelope-from chris@monochrome.org) Received: from mail.monochrome.org (b4.ebbed1.client.atlantech.net [209.190.235.180]) by mx1.freebsd.org (Postfix) with ESMTP id EE2468FC14 for ; Fri, 8 Jun 2012 01:14:12 +0000 (UTC) Received: from [192.168.1.11] ([192.168.1.11]) by mail.monochrome.org (8.14.3/8.14.3) with ESMTP id q581EBFM027147; Thu, 7 Jun 2012 21:14:11 -0400 (EDT) (envelope-from chris@monochrome.org) Date: Thu, 7 Jun 2012 21:14:11 -0400 (EDT) From: Chris Hill To: Fbsd8 In-Reply-To: <4FD1360D.1060208@a1poweruser.com> Message-ID: References: <4FD1360D.1060208@a1poweruser.com> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: FreeBSD Questions 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:14:13 -0000 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 chris@monochrome.org ** [ Busy Expunging ]