Merge pull request #231 from dylanaraps/uptime_fixes

OSX and BSD uptime fixes.
This commit is contained in:
Dylan Araps 2016-04-29 11:10:05 +10:00
commit 854f9e505e

View file

@ -586,37 +586,44 @@ getuptime () {
uptime=$((now - boot))
# Convert uptime to days/hours/mins
mins=$((uptime / 60%60))
minutes=$((uptime / 60%60))
hours=$((uptime / 3600%24))
days=$((uptime / 86400))
# Format the output like Linux's "uptime -p" cmd.
if [ "$mins" == 1 ]; then
uptime="$mins minute"
elif [ "$mins" != 0 ]; then
uptime="$mins minutes"
fi
case "$minutes" in
1) minutes="1 minute" ;;
0) unset minutes ;;
*) minutes="$minutes minutes" ;;
esac
if [ "$hours" == 1 ]; then
uptime="$hours hour, $uptime"
elif [ "$mins" != 0 ]; then
uptime="$hours hours, $uptime"
fi
case "$hours" in
1) hours="1 hour" ;;
0) unset hours ;;
*) hours="$hours hours" ;;
esac
if [ "$days" == 1 ]; then
uptime="$days day, $uptime"
elif [ "$days" != 0 ]; then
uptime="$days days, $uptime"
fi
case "$days" in
1) days="1 day" ;;
0) unset days ;;
*) days="$days days" ;;
esac
uptime="up $uptime"
[ ! -z "$hours" ] && \
[ ! -z "$minutes" ] && \
hours+=","
[ ! -z "$days" ] && \
[ ! -z "$hours" ] && \
days+=","
uptime="up $days $hours $minutes"
;;
esac
# Make the output of uptime smaller.
case "$uptime_shorthand" in
"on")
uptime=${uptime/up}
uptime=${uptime/up }
uptime=${uptime/minutes/mins}
uptime=${uptime/minute/min}
uptime=${uptime/seconds/secs}
@ -624,7 +631,7 @@ getuptime () {
;;
"tiny")
uptime=${uptime/up}
uptime=${uptime/up }
uptime=${uptime/ days/d}
uptime=${uptime/ day/d}
uptime=${uptime/ hours/h}