The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
logrotate doesn't do daily rotation....help required dvrmc UNIX for Dummies Questions & Answers 2 02-01-2008 05:00 AM
Log rotation on HP-UX untamed HP-UX 3 10-01-2007 06:10 AM
What are tr.pid.rotation files? zackz UNIX for Advanced & Expert Users 3 01-23-2007 05:13 PM
Script tool yotoruja Shell Programming and Scripting 4 10-31-2003 11:10 AM
scripts for rotation and compression of sys logs fireblade Filesystems, Disks and Memory 1 02-26-2002 09:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-10-2003
yelalouf yelalouf is offline
Registered User
  
 

Join Date: Sep 2001
Location: Israel
Posts: 5
Log Rotation Tool/Script

Hello all

Does anyone has an intersting script or a good freeware tool for log rotation that is good for Unix and Linux as well ?

My thanks in advance
  #2 (permalink)  
Old 12-10-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
all you need to do is check the file size and or date of the log you want to rotate.

@log=qw(/var/adm/messages /var/log/syslog);
if (file to big || is not from today) {then move it or something;}

its actually alot easier then it might sound.
post where you are stuck.

linux and any enterprise OS should have something to rotate the logs automaticly via cron.
  #3 (permalink)  
Old 12-11-2003
kduffin's Avatar
kduffin kduffin is offline Forum Advisor  
UN1X
  
 

Join Date: Nov 2003
Location: Maryland
Posts: 449
It does depend on whether a given logfile is actually being closed by the process that is writing to it. Programs that write to logfiles often keep the file descriptors open for their logfiles. The file descriptor refers to the inode on the filesystem, so removing/moving a file within a filesystem will mean the process will continues to write to the renamed file.

If the file is removed the kernel is merely unlinking it from a directory, but because the file descriptor referring to it still exists, the file itself can still be written to.

Typically you get a syslog daemon to close its file-descriptors by
sending a HUP to it, although this is mere convention.

You can look at: http://iain.cx/src/logrotate/ - most Linux flavors come with a logrotate script in place already.

Just a case in point:

Looking at syslog:
# ls -l syslog
-rw-r--r-- 1 root other 5078349 Dec 10 22:54 syslog

What process has it open:
# fuser -u syslog
syslog: 26317o(root)

Move the file:
# mv syslog syslog.20031210

Inode is still associated with the new file and held open by the process:
# fuser -u syslog.20031210
syslog.20031210: 26317o(root)

Syslog will keep writing to syslog.20031210 until a HUP (kill -HUP) is sent to syslog (only works under some flavors of unix), or syslog is restarted.

Cheers,

Keith
  #4 (permalink)  
Old 12-11-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
I kinda like newsyslog.
  #5 (permalink)  
Old 12-17-2003
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Here is a link to a thread where we came up with a perl solution for automagic log rotating based upon number of entries. This by-passes syslogd so it might or might not be useful to you.

http://www.freebsdforums.org/forums/...3949#post13949

The perl code is as follows:

Code:
#!/usr/bin/perl

# Real cheezy attempt at piping STDOUT into a perl routine to automagically
# rotate logs. Idea inspired by cRock.
# Auswipe sez "Hey, no guarantees!"

my $lineCounter = 0;
my $logCount    = 1;

#open(LOGFILE, ">app.log.$logCount");

while (true) {
  if (($lineCounter > 1000) || ($lineCounter == 0)) {
    close(LOGFILE);
    open(LOGFILE, ">app.log.$logCount");
    $logCount++;
    $lineCounter = 1;
    # print STDERR "Rolled log to app.log.$logCount\n";
  };
  $logEntry = <STDIN>;
  $lineCounter++;
  print LOGFILE "$logEntry";
  #print STDERR "Made log entry.\n";
};
Sample usage:

Code:
./someapp | ./perl_buffer
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0