When I execute following command to get cpu usage , I get nice + user cpu usage.
top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'
Output:
14.5
Here I am getting problem is that the output depends on top command thus it doesn't change instantly as top command. So I am not getting correct cpu instantly. It gives same output and not changing.
I want to get real-time cpu usage in output. Please help me to improve my command.