From b757734a66fc72df4c789fc46ac0553bb2328bcd Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 23 Apr 2018 08:45:10 +0200 Subject: bin/get_cpu_status: Make script support macOS by using ps). --- bin/get_cpu_status | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/get_cpu_status b/bin/get_cpu_status index 18b5c16..d8580db 100755 --- a/bin/get_cpu_status +++ b/bin/get_cpu_status @@ -4,7 +4,11 @@ IFS=$'\n\t' proc_output="" -proc_output=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf("%5.1f", usage)}') +if [ "$(uname)" == "Darwin" ]; then + proc_output=$(ps -A -o %cpu | awk '{s+=$1} END {print s}') +else + proc_output=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf("%5.1f", usage)}') +fi proc_output=${proc_output#" "} echo "$proc_output%" -- cgit v1.2.3-70-g09d2