How to check log size every 10min. by script (can use crontab)
if log size not change with alert "Log not update"
Base run on SunOS 5.8 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise
logFiles="log1.log log2.log"
logLocation="/usr/home/test/log/"
Out put.
Tue Jan 31 16:24:03 ICT 2013
log1.log :: Log not running :: Pls Check Service 1 minute.
log2.log :: Log not running :: Pls Check Service 2 minute.
Tue Jan 31 16:25:03 ICT 2013
log1.log :: Log not running :: Pls Check Service 3 minute.
log2.log :: OK
Tue Jan 31 16:26:04 ICT 2013
log1.log :: Log not running :: Pls Check Service 1 minute.
log2.log :: Log not running :: Pls Check Service 2 minute.
Tue Jan 31 16:27:04 ICT 2013
log1.log :: Log not running :: Pls Check Service 3 minute.
log2.log :: Log not running :: Pls Check Service 4 minute.
this is a simple script . can it help find your way ?
os=ofs #old size
logFile=logFile
# test log file exists !
test -r $logFile || { echo "can't open $logFile"; 1>&2; exit 1; }
# get current log file size !
cfs=`ls -l $logFile | awk '{print $5}'`
# test to see file that keeps old size exists !
test -r $os || { echo 'not changed' 1>&2; echo $cfs>$os; exit 1; }
# old file size is empty !
if test `ls -l $os | awk '{print $5}'` -eq 0
then
echo 'not changed' 1>&2;
exit 1;
fi
oldsize=`sed -n '1,1p' $os`
if test $oldsize -eq $cfs
then
echo 'not changed' 1>&2
else
echo 'changed' 1>&2
fi
echo $cfs >$os
certainly above code with its structure can be write better and more efficient . i wrote it very quickly with my limited skill .
I'm use crontab.
#!/bin/ksh
#===============================================================================
#########################################
# Main Program
#########################################
msf_file=/usr/home/log/SMDB_m4_Tx.log
msf_size=`ls -l $msf_file|awk '{ print $5 }'`
sleep 600
msf_size1=`ls -l $msf_file|awk '{ print $5 }'`
if [ $msf_size -eq $msf_size1 ]; then
echo SMDB_m4_Tx.log NOT OK.
else
echo SMDB_m4_Tx.log OK.
fi