Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit an opened file

Status
Not open for further replies.

swhunter

Programmer
Jan 28, 2003
1
US
We're running a server program that keep adding message into a log file, and it's supposed to run 24/7. Is there any way that we can edit this log file or clean it up while it's still available for the server program. We are using script below in our cron script; however, the server loses the file pointer and won't be able to log the message right after this script is called. Is there any command to accomplish this in Unix?
Thank you.

mv $1 $1.$$
grep -v $2 $1.$$ >> $1
rm $1.$$
 
Try changing the first mv to a cp, that way the original inode is retained and it may continue to write to the file after its been cleaned up.

You'll also need to change >> to > if you use this method.

Unfortunately some programmes remember the exact offset they were writing to in the file, so if you reduce the log file from 4MB to 1MB, say, they still write at the 4MB offset and the file size just jumps up to 4MB again as soon as more data is written to the log. Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top