Merge pull request #179 from dylanaraps/openbsd_fixes

OpenBSD fixes
This commit is contained in:
Dylan Araps 2016-03-26 10:15:26 +11:00
commit 40eb97a48a
1 changed files with 18 additions and 11 deletions

View File

@ -587,22 +587,24 @@ getuptime () {
# Format the output like Linux's "uptime -p" cmd. # Format the output like Linux's "uptime -p" cmd.
if [ "$mins" == 1 ]; then if [ "$mins" == 1 ]; then
uptime="up $mins minute" uptime="$mins minute"
elif [ "$mins" != 0 ]; then elif [ "$mins" != 0 ]; then
uptime="up $mins minutes" uptime="$mins minutes"
fi fi
if [ "$hours" == 1 ]; then if [ "$hours" == 1 ]; then
uptime="up $hours hour, ${uptime/up }" uptime="$hours hour, $uptime"
elif [ "$mins" != 0 ]; then elif [ "$mins" != 0 ]; then
uptime="up $hours hours, ${uptime/up }" uptime="$hours hours, $uptime"
fi fi
if [ "$days" == 1 ]; then if [ "$days" == 1 ]; then
uptime="up $days day, ${uptime/up }" uptime="$days day, $uptime"
elif [ "$days" != 0 ]; then elif [ "$days" != 0 ]; then
uptime="up $days days, ${uptime/ up}" uptime="$days days, $uptime"
fi fi
uptime="up $uptime"
;; ;;
"Windows") "Windows")
@ -864,6 +866,7 @@ getcpu () {
"OpenBSD"* | "FreeBSD"*) "OpenBSD"* | "FreeBSD"*)
# Get cpu name # Get cpu name
cpu="$(sysctl -n hw.model)" cpu="$(sysctl -n hw.model)"
cpu=${cpu/[0-9]\.*}
cpu=${cpu/ @*} cpu=${cpu/ @*}
cpu=${cpu// } cpu=${cpu// }
cpu=${cpu% } cpu=${cpu% }
@ -1133,15 +1136,19 @@ getmemory () {
"OpenBSD" | "BSD") "OpenBSD" | "BSD")
case "$distro" in case "$distro" in
"OpenBSD"* | "FreeBSD"*) "OpenBSD"*)
mem=($(top -d 1 | awk -F ': |/| |M' '/Memory:/ {printf $4 " " $6 " " $11 "\n"}'))
memtotal=$((${mem[1]} + ${mem[2]}))
memused=$((memtotal - ${mem[0]}))
memory="${memused}MB / ${memtotal}MB"
;;
"FreeBSD"*)
memtotal=$(dmesg | awk '/real mem/ {printf $5}') memtotal=$(dmesg | awk '/real mem/ {printf $5}')
memtotal=${memtotal/\(} memtotal=${memtotal/\(}
memtotal=${memtotal/MB\)} memtotal=${memtotal/MB\)}
case "$distro" in memfree=$(top -d 1 | awk '/Mem:/ {printf $10}')
"OpenBSD"*) memfree=$(top -d 1 | awk '/Real:/ {printf $6}') ;;
"FreeBSD"*) memfree=$(top -d 1 | awk '/Mem:/ {printf $10}') ;;
esac
memfree=${memfree/M} memfree=${memfree/M}
memused=$((memtotal - memfree)) memused=$((memtotal - memfree))