CPU usage shell script

This three-liner extracts the CPU idle-percentage from vmstat, subtracts it from 100 and stores the result in a file.
Vmstat arguments specify waiting time in seconds and number of captures. I chose {5,2} to be sufficient.

idle=`vmstat -n 5 2 | tail -n 1 | sed -e 's/ \{2,\}/ /g' | cut -d" " -f16`
use=$((100-$idle))
echo $use >> load

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?