Solved

Rotating Logs w/o Knowing Who is Writing Them

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

690 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