Application still updating Log files even after name has been changed

I have a WebSphere service which creates an Applicaiton Log everytime the JVM is restarted.  However we need the application logs to be recycled every night (at midnight).  I've written a short Korn Shell script to 'mv' the files to a new name (appended with the date) but afterwards the files are still updated by the application.

Why is this the case if the file name is different? Or am I missing some knowledge regarding how the file system updates?  Should I infact 'copy' the file to the new appended filename (with date) and null the application log file? or is there a 'cleaner' way of approaching this?

Cheers
london_mccourtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pétur Ingi EgilssonSoftware Engineer -- ConsultantCommented:
Move the logfile.log to logfile.date.log
gunzip logfile.date.log
touch logfile.log
0
Pétur Ingi EgilssonSoftware Engineer -- ConsultantCommented:
reason i gunzip logfile.date.log is so it's no longer marked as a text file
0
omarfaridCommented:
I think once the file is opened, the process will refer to it by file descriptor. Hence moving the file will not stop process from  writing to it.

Why don't you copy the file, then truncate it by

cp /dev/null /path/to/logfile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

sjm_eeCommented:
As omarfarid said, once open, the appliation refers to the file by file descriptor and therefore by inode, and inode is unchanged by move, rename and copy. Further, truncating the file as omarfarid suggests will not have any effect because as long as the applciaiton has the file open it will write to that file via the file descriptor at the current byte offset.

You need to stop the process writing to the file, then rotate the log files, and then restart the process. This may not be possible in your environment.

Is the Websphere service a standard part of Websphere or something that has been added locally? If the latter, you may be able to get the code changed to support the behaviour that you require.
0
Pétur Ingi EgilssonSoftware Engineer -- ConsultantCommented:
If the process does not have a lock on the file, can't he simply copy it to filename.date.log.old and then `echo > filename.log` to empty it?
0
omarfaridCommented:
Hi sjm_ee,

I ran a shell script in the background to keep writing to a file (the file keep growing) and then copied /dev/null to this file and it did truncate. The other background process then wrote to it and the file size shrank.



0
omarfaridCommented:
Hi PeturIngiEgilsson,

What you said is the same as mine except you echo null to the file and I copy null to the file :)

0
omarfaridCommented:
Hi PeturIngiEgilsson,

I have the following comment on your 1st comment / solution:

moving / renaming the file and then recreating it with touch command may not create it with the same permissions and ownership, while copy /dev/null will preserve those.
0
Duncan RoeSoftware DeveloperCommented:
I think you need to persuade the logging application to open a new log file.  One way would be: rename log file; kill server that is writing to it; restart server
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.