"sed" to check file size & echo " " to destination file

Hi,

I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set back to zero.
If somebody can help me with a sed command to check the size of messages & to do a echo "" > messages ,if the size is greater than 128KB, I'll really grateful.

Wishes
Jay

You could actually use find!

find /var/log -name messages -type f -size +131072c

Thanks....

Now I'm using a busybox find, which doesn't have support for "-size" argument
So i think a sed command that meets the requirement would be great.
Please provide a sed command to check the file & then flush that file.

Wishes
Jay

Then it would help to know how you intend to use sed.

What does the output from "ls -ld /var/log/messages" look like?

Hi Porter,

The output of
root@WiMAX-BS:/var/log ls -ld /var/log/messages
-rw------- 1 root root 41994 Jan 23 03:16 /var/log/messages

==========

Well.. I was thinking like
1) use the ls command grab the size value using the sed and
2) then if it is greater than 128KB, do an echo " " > /var/log/messages

Now I've crond support, so I can add a script with above logic to cron job.

Thanks
Jay

#!/bin/sh

LOG=/var/log/messages

fifth()
{
     echo $5
}

SIZE=`ls -ld $LOG`
SIZE=`fifth $SIZE`

if test "$SIZE" -gt 131072
then
      date >$LOG
fi

Oh!! That works!

Thanks a lot Porter...
Have a nice day.

Wishes
Jay

you can use the following script to have a copy from the old messages file or you can remove it

#!/bin/ksh

SIZE=128
MESS_SIZE=`du -k /var/adm/messages |awk '{ print $1 ; }' `
if [ $MESS_SIZE -gt $SIZE ] ;
then
mv /var/adm/messages /var/adm/messages.1
#or you can remove it
#rm /var/adm/messages
touch /var/adm/messages
fi