Solved

Rotating Logs w/o Knowing Who is Writing Them

Posted on 2006-11-20
3
217 Views
Last Modified: 2013-12-27
I need to rotate some logs that are produced by an externally developed application.  It is mostly C code so we have very little insight into what they are "really" doing.  To find out who needs to be HUPped I need to jump through political hoops and politics is not my thing.

Is there a way to use a shell script or Perl to rotate a log in a way that will not disturb the applicaiton that is writing it?

Thanks, Allan
0
Comment
Question by:huffmana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:huffmana
ID: 17981859
Discovery (at least for me:)
# fuser filename
Shows the process IDs of the  processes that are using the files specified as arguments.  So if a C program has the file open, it should show up with the fuse command.

If no process is "using" the file it should be possible to "cat /dev/null > finename" after rolling the log to a saved version.  So the question is, if a file is being "used" by a process, is it safe to "cat /dev/null > finename" while it is being used.  I don't think that I can simply -HUP the process using the PID because there are many dependancies between processes that are running.

In any case, logadm seems like the best tool for rolling the logs....
0
 
LVL 6

Accepted Solution

by:
bpeterse earned 500 total points
ID: 17982458
I don't think you'd want to 'cp /dev/null > {filename}' while it is still writing to that file.  Better to 1) cp {logfile} {logfile.old} and 2) cp /dev/null > {filename}.  It's much safer this way - and basically how most log rotaters work.

Also - if you want to know what this C program is doing - and have a bit of patience in deciphering the output - you can truss the process that is running:

truss -feo <output_file> {process_command}  OR
truss -feo <output_file> -p PID
0
 

Author Comment

by:huffmana
ID: 17986938
Very Cool :-)  I love Unix.  There is always another level that is accessible if you want to dig.  Each time that I think that I have a deep knowledge, another level is revealed and I realize that I am just a beginner.  And I have not even scratched the surface by examining the source code that is available with Solaris 10.  Funny how real programming is still done with “C” code instead of all these “wonderful” OOD languages.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question