ok guys
I'm a noob.
i started to use red hat linux entrprise edition 1 week ago and im trying to write a bash script.now Im stucked.

Im trying to write a utilization program.
The problem is:

i could get the memory cpu and disk utilization. program wrotes those informations into files. now im trying to take the result's average. but i have a program with reading from file and taking the average. can somebody help me !!!

My code:
Code:
#!/bin/bash

login=admin1
port=23
password=test
Host=localhost
Utilizationlog=$Host.log
Ramlog=Ram.log
Disklog=Disk.log
Cpulog=Cpu.log
AverageRamlog=AverageRam.log
AverageDisklog=AverageDisk.log
AverageCpulog=AverageCpu.log
sumof=0
sumof1=0
sumof2=0
sum=1
temp=1

echo -n "Hostname: "
read Host
echo -n "Password: "
read password


main(){


(sleep 1; echo ${login}; sleep 1; echo ${password}; 
echo  "=================================================" >> $Utilizationlog;
echo " " >> $Utilizationlog;
echo  "Hostname: ${Host}" >> $Utilizationlog;
echo `date '+Date: %d/%m/%y%nTime: %H:%M:%S'` >> $Utilizationlog;
echo " " >> $Utilizationlog;
echo  "Total Used Free (RAM Usage:MB Format)" >> $Utilizationlog;
echo `free -m | grep Mem | awk '{print $2, $3, $4}' >> $Utilizationlog`;
echo  "Size Used Available Use% (Disk usage:GB Format)" >> $Utilizationlog;
echo `df -h | grep "4" | awk '{print $1, $2, $3, $4}' >> $Utilizationlog`;
echo  "Use% Sy% id% Wa% (CPU Usage)" >> $Utilizationlog;
echo `vmstat | grep "3" | awk '{print $13, $14, $15, $16}' >> $Utilizationlog`;
echo `free -m | grep Mem | awk '{print $2, $3, $4}' >> $Ramlog`;
echo `df -h | grep "4" | awk '{print $1, $2, $3, $4}' >> $Disklog`;
echo `vmstat | grep "3" | awk '{print $13, $14, $15, $16}' >> $Cpulog`;

echo "exit") | telnet ${Host}

}

calculate(){

for i in  `awk '{print $1}' Ram.log`; do

awk '{ temp = $i+ temp}' >> $AverageRamlog
#temp = $i+ temp
echo ` $temp ` >> $AverageRamlog;
#awk '{ $sum = $i + $sum ; $sum }' >> $AverageRamlog

#awk 'NF > 0' Ram.log

#awk '{ sum = $1 + $2 ; avg = sum / 3 ; print $1, avg }' $AverageRamlog

 

#for j in  `awk '{print $2}' Ram.log`; do
#$sumof1+=$j;
done  
#for k in  `awk '{print $3}' Ram.log`; do
#$sumof2+=$k;
#done  


#echo " $sumof " >> $AverageRamlog;

}

#BEGIN{ s += $1 }
   #    { p += $2 }
    #   { k += $3 }
  #END  { print "=================================================" } >> $AverageRamlog;
     #  { print " "} >> $AverageRamlog;
      # { print "Total Used Free  (Average of RAM Usage:MB Format) Days:", NR } >> $AverageRamlog;
       #{ print s/NR, p/NR, k/NR } >> $AverageRamlog;
       



   
#calram(){

#for i in  `awk '{print $1 }' $Utilizationlog`; do
# $i;
# done

#done

 #exec<$fname

#echo a sayısını giriniz
#read a
#echo b sayısını giriniz
#read b

#let "cikan=b-a"
                 
               # echo $cikan
              #  ;;

main
calculate

#calram
#caldisk
#calcpu

exit 0