Skip to content
Advertisement

Bash alias cpu usage

I’ve tried this command but I have a percentage error calculator:

alias cpu="mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12"%" }'"

Thank you for help

Advertisement

Answer

Change it to this:

alias cpu="mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12"%" }'"

was missing after 100 -.

-> mpstat
Linux 3.2.0-69-virtual (myhost)     01/06/2017  _x86_64_    (8 CPU)

10:18:16 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
10:18:16 PM  all   12.06    7.00    7.96    0.02    0.00    0.24    0.22    0.00   72.49

-> cpu
27.51%
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement