Listing 1 Script to trim the SNMP collected data to
last 2000 entries
#!/bin/sh
# ------------------------------------------------------------
# Script to trim the SNMP collected data to last 2000 entries
# This way we can archive the old entries rather than filling
# up the disk space and slowing down the system
# Version 1.0
# ------------------------------------------------------------
cd /var/opt/OV/share/databases/snmpCollect/
ll /var/opt/OV/share/databases/snmpCollect/|grep "!" |awk \
'{print $9}'|sed 's/!//g' >/var/opt/OV/share/tmp/collect_data_files
FILE=/var/opt/OV/share/tmp/collect_data_files
cat /dev/null>/var/opt/OV/share/tmp/collect_data_files_trim
while read LINE
do
for i in $LINE
do
if [ -s $i ]
then
echo $i>>/var/opt/OV/share/tmp/collect_data_files_trim
fi
done
done <$FILE
FILETRIM=/var/opt/OV/share/tmp/collect_data_files_trim
LOGFILE=/tmp/snmpcoldatatrim.log
echo "SNMPCOLLECT DATA TRIm BEGINS" >$LOGFILE
while read LINE
do
for i in $LINE
do
echo "Trimming of $i starts now" >>$LOGFILE
lineno=`snmpColDump $i | wc -l`
if [ $lineno -gt 2000 ]
then
lineno=`expr $lineno - 2001`
else
lineno=1
fi
snmpColDump -tTI $i | sed -n $lineno',$p' |
awk -F\t '{printf("%d\t%d\t%s\t%lg\n", $4, $5, $6, $3)}' |
snmpColDump -r - $i
/usr/bin/rm $i~
echo "Trimming of $i finished now" >>$LOGFILE
done
done <$FILETRIM
|