diff options
author | David Runge <david.runge@native-instruments.de> | 2018-04-23 08:45:10 +0200 |
---|---|---|
committer | David Runge <david.runge@native-instruments.de> | 2018-04-23 08:45:10 +0200 |
commit | b757734a66fc72df4c789fc46ac0553bb2328bcd (patch) | |
tree | 8ce275668d008f3f28206ec70a24cbd10659abdf | |
parent | 33824987fd7d8764288bcd1814ada49a16a68f15 (diff) | |
download | dotfiles-b757734a66fc72df4c789fc46ac0553bb2328bcd.tar.gz dotfiles-b757734a66fc72df4c789fc46ac0553bb2328bcd.tar.bz2 dotfiles-b757734a66fc72df4c789fc46ac0553bb2328bcd.tar.xz dotfiles-b757734a66fc72df4c789fc46ac0553bb2328bcd.zip |
bin/get_cpu_status: Make script support macOS by using ps).
-rwxr-xr-x | bin/get_cpu_status | 6 |
1 files changed, 5 insertions, 1 deletions
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%" |