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"

Reply via email to