Created
March 3, 2014 00:38
-
-
Save raidzero/9316404 to your computer and use it in GitHub Desktop.
Get last boot time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# get the last boot time and display it in 12 hour format | |
# USAGE: lastboot.sh [date|time|both] | |
LASTBOOT_LINE=`last | grep reboot | head -n 1` | |
DATE=`echo $LASTBOOT_LINE | awk '{print$5,$6,$7}'` | |
TIME=`echo $LASTBOOT_LINE | awk '{print$8}'` | |
#convert to 12 hour | |
HOUR=`echo $TIME | cut -d : -f1` | |
MIN=`echo $TIME | cut -d : -f2` | |
if [ $HOUR -ge 12 ] && [ $HOUR -le 23 ]; then | |
AMPM="PM" | |
let HOUR=$HOUR-12 | |
elif [ $HOUR -ge 1 ] && [ $HOUR -le 11 ]; then | |
AMPM="AM" | |
HOUR=$HOUR | |
fi | |
if [ $HOUR -eq 0 ]; then | |
AMPM="AM" | |
HOUR=12 | |
fi | |
TIME="$HOUR:$MIN $AMPM" | |
if [ "$1" == "both" ]; then | |
echo "$DATE $TIME" | |
elif [ "$1" == "time" ]; then | |
echo "$TIME" | |
elif [ "$1" == "date" ]; then | |
echo "$DATE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment