Solved

Rotating Logs w/o Knowing Who is Writing Them

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix, date minus 1, 2 or 3 days (last working day) 11 94
OpenLDAP Proxy to Active Directy 6 555
Image not there 4 74
Authenticate using sesu from script 7 158
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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 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…
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.

737 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