Logfile Size exceeded ????

Hi,

How to write a script which checks the size of a log file?
I want that the log file contents to get cleared as soon as it increases 1 KB.

Thanks

You can do something like:

#!/bin/ksh

used=`du -b logfile|awk '{print $1}'`
if [ "$used" -gt 1024 ]; then
  # do your stuff here
fi

Regards

ThanQ Franklin !!!

#! /usr/bin/ksh

interval=900 ## check for logfile size once in this much seconds

while true ; do
size_of_file=`ls -l logfile | awk '{ print $5}'`

if [ ${size_of_file} -ge 1024 ]
then
datestamp=`date "+%m%h%Y_%H%M%S"
cp logfile /archive/logfile.${datestamp} ## take an archive
cp /dev/null logfile
fi
sleep $interval

done