Unix shell script to get CPU usage
#!/bin/bash
id=0; tot=0; p_id=0; p_tot=0;
for ((i=0; $i < 100; ++i )) ; do
p_id=$id; p_tot=$tot;
x=`cat /proc/stat | grep -w cpu`;
id=`echo $x | cut -d " " -f 5`;
tot=0;
for f in `echo $x`; do
tot=$(($tot + $f));
done;
echo "idle CPU usage is % = "$((($id - $p_id)*100/($tot - $p_tot)));
sleep 3;
done
Thanks for this useful shell script.
ReplyDeletetop command in unix