Solved

Rotating Logs w/o Knowing Who is Writing Them

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

775 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