Solved

Rotating Logs w/o Knowing Who is Writing Them

Posted on 2006-11-20
3
213 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now