1) The error is probably coming from this line:
Code:
RAM Information for last 10 Seconds
Which is the first line of the file, and which AWK is interpreting (or trying to) as numbers, which it is not, hence division by zero. You need a method of skipping over that first line of the file, or selecting only the lines which actually have the numerical data that you want. Also, AWK can read files all by itself, so you don't really need that `cat` there. I would try something like below, which places a simple regexp (
regular
expression) into the awk, which will match only the lines beginning with "Mem:" and ignore the rest:
Code:
awk '/^Mem:/ { print $3 / $2}' /tmp/raminfo
2) I'm not sure if the desired output you want from this is a XX/YY format, or if you actually planned to do that division operation $3/$2, but if you want the division thing, you may wish to multiply the result by 100 to get a percent, which would be maybe more pleasing to the eye. OR, if you just want a display of XX/YY then you'll need to put the / into "double quotes".
3) Finally a suggestion/idea which is maybe just a matter of preference for me: when doing simple shell math, you could use
i=$((i+1)) instead of
i=$( expr $i + 1 ) if for no other reason than that there are three less characters to type
but it's up to you.
Cheers!