Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Jun 2012 20:24:49 -0500
From:      Chris <racerx@makeworld.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: find date of last boot
Message-ID:  <4FD15461.6090109@makeworld.com>
In-Reply-To: <alpine.BSF.2.00.1206072110350.67420@tripel.monochrome.org>
References:  <4FD1360D.1060208@a1poweruser.com> <alpine.BSF.2.00.1206072110350.67420@tripel.monochrome.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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
 <><



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4FD15461.6090109>