Here is the command which gives the total CPU usage in %
top -bn1 | grep "Cpu(s)" | \sed "s/.*, *\([0-9.]*\)%\id.*/\1/" | \awk '{print 100 - $1"%"}'
Here is another command in which, we can write the conditions to display the results. Below is the example which display the process names which exceeds by given $cpuUtil value.
$cpuUtil = 2
ps -e -o pcpu -o args --no-heading | sort -k 1 -r | awk '$1 > $cpuUtil { print $2 }'
top -bn1 | grep "Cpu(s)" | \sed "s/.*, *\([0-9.]*\)%\id.*/\1/" | \awk '{print 100 - $1"%"}'
Here is another command in which, we can write the conditions to display the results. Below is the example which display the process names which exceeds by given $cpuUtil value.
$cpuUtil = 2
ps -e -o pcpu -o args --no-heading | sort -k 1 -r | awk '$1 > $cpuUtil { print $2 }'
No comments:
Post a Comment