truncate file script is not working

Hi All,
I have an application which writes log in to a file. The file size becomes around min of 800 MB a day. So I have written a script which backup the file and truncate the original file. My script is like this

cp X.log /backup/X.log1
> X.log

But the second truncate command is not working properly.The file is truncated to 0 byte but whenever the application writes the next log the file size is coming to the previous original size.

Can anyone please guide how to truncate the file properly.

Thanks in Advance
Venkat

Try this


cp X.log /backup/X.log1
string X.log > X.log

Thanks,
Sam

From what you are describing, the truncate command is working - setting to zero bytes. It's just that the application immediately rewrites it. The question is why does it start at the previous original size? Is that different than when the log is first created? If it is different, what data gets written to account for the extra space? Is the application somehow tracking where to write to log?

Hi,
Your doubt is right. The application was opening the log file in the WRITE mode but not in APPEND mode. That is why even if I truncate the file, the application doesnt know about the change in the offset of the log file. So the application was writing the log after the next offset what it was previously but not from the starting.
I have changed the configurations so that the application opens the log file in APPEND mode and it is working now.

Thanks all.