The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Truncate multiple file extensions prvnrk Shell Programming and Scripting 12 04-04-2008 10:20 AM
Truncate last <n> characters from a file Gwailo88 UNIX for Dummies Questions & Answers 1 03-05-2008 12:52 AM
Truncate File contain rinku Shell Programming and Scripting 2 05-30-2007 06:43 AM
how to truncate a large (8 GB) file kotasateesh Shell Programming and Scripting 1 07-05-2006 01:57 AM
Truncate what is It? rocker40 UNIX for Dummies Questions & Answers 2 10-11-2003 07:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-19-2007
mvenkat_in mvenkat_in is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 2
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
  #2 (permalink)  
Old 10-22-2007
Serious Sam Serious Sam is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 14
Try this

Code:

cp X.log /backup/X.log1
string X.log > X.log
Thanks,
Sam
  #3 (permalink)  
Old 10-22-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Quote:
Originally Posted by mvenkat_in View Post
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.
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?
  #4 (permalink)  
Old 10-24-2007
mvenkat_in mvenkat_in is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 2
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0