Skip to content

Commit f15c2c3

Browse files
Create CPU-usage.sh
1 parent b5a2a89 commit f15c2c3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CPU-usage.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
main() {
3+
local prefix
4+
cpu_usage_total=$(top -b -n2 -p 1 | grep -F "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }')
5+
echo "Total CPU usage: $cpu_usage_total"
6+
}
7+
main "$@"

0 commit comments

Comments
 (0)