aboutsummaryrefslogtreecommitdiffstats
path: root/bin/get_cpu_status
blob: d8580db86221b611d41bfac372864af9800bcbe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

proc_output=""

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%"
exit 0