Hi. 1/ What platform are you on? 2/ Are you the System Administrator?
3/ There is on Solaris and Linux usually a script that would do log rotation. There would not be a need to take down the process, but rather do the following (assuming you have the rights): mv <logfile> <logfile.n> n = number 0-9. If file <logfile.0> already exists, that should be rotated to <logfile.1> and so on. <logfile.9> is usually "dropped"... After the file has been moved send a SIGHUP to the PID of the appropriate process, and you are done. This ensure that the process starts writing to <logfile> again. If no SIGHUP is sent, the process will continue to write to the old log file, which is now <logfile.0>... For a further explanation on this, read up on inodes and how they work.. ;) If you already have a log rotation scheme in place, utilize that as opposed to inventing the wheel again. ;) Hope this clears up any questions. Best Regards Anders Holm Critical Path Technical Support Engineer ---------------------------------------------------------------------- Tel USA/Canada: 1 800 353 8437 Tel Worldwide: +1 801 736 0806 E-mail: [EMAIL PROTECTED] Internet: http://support.cp.net > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] > Sent: 28 June 2002 22:04 > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: RE: updating a file in place is almost working > > > I think you will have a problem unless somehow you can tell the > service that you want to update the file. As long as the process has that > file open, it will not change where it is writing to regardless > of renaming > and moving. > > The process that is generating the logfile: is it one you can make > mods to or not? If make mods, then have it take care of the > logfile on daily > basis itself. If not, then you wouldneed to stop and restart the process. > There might a Unix guru on the list who can tell you otherwise. > > Wags ;) > > -----Original Message----- > From: Rice, Elizabeth A. [mailto:[EMAIL PROTECTED]] > Sent: Friday, June 28, 2002 11:23 > To: '[EMAIL PROTECTED]' > Subject: updating a file in place is almost working > > > We have a log file that gets really huge, so I wanted to to edit > it in place > to delete old entries and only leave today's entries in the current log. > The process writing to the log doesn't come down for months at a time. > Old entries should get written to an archive file. > The whole thing should get backed up. > The existing log should only have today's entries in it after the > process is > complete. > > Here's what I have coded so far.... > > > > > $logcopy="${logdir}/${logfile}.archive"; > > > > open (LOGCOPY, ">${logcopy}") or die ("Cannot open $logcopy \n"); > > @ARGV = ("${logdir}/${logfile}"); # prime the diamond operator > > $^I = ".bak"; # write $logfile.bak for backup > > while (<>) { > > #print $_; > > #print "todayfound is $todayfound \n"; > > if ($todayfound eq "y") { # if today's date has already been > found > print; # write to ARGVOUT, the new logfile > > } elsif (m/($weekday)\s+ # match for today's weekday, spa > > ($month)\s+ # and today's month, spaces > > (\d+)/x # and one or more digits > > and $3 == $day){ # and digits are day of month > > $todayfound="y"; # then set flag for date found > > print; # write to ARGVOUT, the new logfile > > } else { # if we have not reached > today's date > > print LOGCOPY; # write the line to the logcopy file > > s#.*\n##; # erase the line > > } > > } > > close (LOGCOPY); > > > > It performs somewhat as expected. > > All entries are still in the .bak file. > Entries prior to today's date go to LOGCOPY, the archive file. > Only today's entries go to $logdir/$logfile, the original file name. > > The problem is that the open process is now writing to the .bak > file instead > of the filename it's defined to go to. If I simply do a move I've got all > the entries back in the log file again. > > Obviously I'm doing something wrong. Help? > > Note: Entries in the log are mutli-line. The format is along the lines > of.... > > [Fri Jun 28 13:17:18 2002] /IS/Listener/0/Informational/0/Build-PQ57139 > Initialization completed, 'Listener' service is online. > > Also, it shouldn't matter, but this is a script under UNIX > Systems Services > on the mainframe. > > Thanks, > Beth > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]