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
1 changed files with 27 additions and 20 deletions

View File

@ -586,30 +586,37 @@ getuptime () {
uptime=$((now - boot)) uptime=$((now - boot))
# Convert uptime to days/hours/mins # Convert uptime to days/hours/mins
mins=$((uptime / 60%60)) minutes=$((uptime / 60%60))
hours=$((uptime / 3600%24)) hours=$((uptime / 3600%24))
days=$((uptime / 86400)) days=$((uptime / 86400))
# Format the output like Linux's "uptime -p" cmd. case "$minutes" in
if [ "$mins" == 1 ]; then 1) minutes="1 minute" ;;
uptime="$mins minute" 0) unset minutes ;;
elif [ "$mins" != 0 ]; then *) minutes="$minutes minutes" ;;
uptime="$mins minutes" esac
fi
if [ "$hours" == 1 ]; then case "$hours" in
uptime="$hours hour, $uptime" 1) hours="1 hour" ;;
elif [ "$mins" != 0 ]; then 0) unset hours ;;
uptime="$hours hours, $uptime" *) hours="$hours hours" ;;
fi esac
if [ "$days" == 1 ]; then case "$days" in
uptime="$days day, $uptime" 1) days="1 day" ;;
elif [ "$days" != 0 ]; then 0) unset days ;;
uptime="$days days, $uptime" *) days="$days days" ;;
fi esac
uptime="up $uptime" [ ! -z "$hours" ] && \
[ ! -z "$minutes" ] && \
hours+=","
[ ! -z "$days" ] && \
[ ! -z "$hours" ] && \
days+=","
uptime="up $days $hours $minutes"
;; ;;
esac esac