#!/bin/sh

# Determine the location of log file for stats
LOG=/etc/snmp/cpu.log

LINES=0

###
intervals=`cat /proc/stat | grep "cpu "`
idle_time=$( echo $intervals | awk '{print $5}' ) 

((total_time=0))
for interval in $intervals
do
	if [[ $interval == cpu* ]]; then continue; fi
 
	((total_time=total_time+$interval))
done

lines_calc() {
if [ -e "$LOG" ]; then
    LINES=$(wc -l $LOG | awk '{print $1}')
fi
}

lines_calc
if [ "$LINES" -le "16" ]; then
echo "$total_time $idle_time" >> /etc/snmp/cpu.log
fi

lines_calc
if [ "$LINES" -gt "16" ]; then
sed '1,1d' $LOG > $LOG.tmp
cat $LOG.tmp > $LOG
fi

exit 0

