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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script for checking and reporting file sizes in a directory. marconi Shell Programming and Scripting 1 04-03-2008 08:00 AM
Script to check and report database file sizes... marconi Shell Programming and Scripting 2 04-02-2008 05:50 AM
Help on adding file sizes llsmr777 UNIX for Dummies Questions & Answers 1 09-18-2007 02:58 PM
Script for file names/sizes ssmiths001 Shell Programming and Scripting 2 05-09-2006 05:55 PM
compare file sizes joli Shell Programming and Scripting 4 02-04-2005 06:52 PM

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

Join Date: Oct 2002
Posts: 5
syslog log file sizes

I am logging the messages from a router network and the log files are getting enormous is there any way to limit the size of the log file by either wrapping it or preferably creating a new one and renaiming the old.

Cheers

mike
  #2 (permalink)  
Old 06-18-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
you can have a cron job that checks the file size.

i.e.


if [ file_size > preset_size ]; then
copy the file || email the file as an attachment
cat_null_into_the_file_to_clear_it_out > file
fi
  #3 (permalink)  
Old 06-18-2003
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,669
For syslog, try this:

# cat $logfile | gzip -9 > $logfile.$date && > $logfile.

This compresses the file as it rotates it, zeros it out and then keeps the same indoe open to any application that might have it open already.

Make sure that this will do what you want though. For instance, if your log files are buffered, or the app reads in the log file for read/write, this might not work. Works fine for syslog:

From:

http://pcunix.com/Bofcusm/315.html
  #4 (permalink)  
Old 06-19-2003
mscomms mscomms is offline
Registered User
  
 

Join Date: Oct 2002
Posts: 5
cheers both I will give this a go
  #5 (permalink)  
Old 06-19-2003
mscomms mscomms is offline
Registered User
  
 

Join Date: Oct 2002
Posts: 5
sorted thanks, here is the complete script

Code:
#!/bin/bash

#######################################################################
#                                                                     #
# Script created mike smith (mike.smith@neosnetworks)                 #
#                                                                     #
#        Last edit 19/06/2003 Ver1                                    #
#######################################################################

# Check logfile is specified in command line

if [ $# -lt 1 ] ; then
        echo
        echo You need to specify the logfile to rotate i.e. /var/syslogs/riverstone
        exit 0
fi

# Set Variables

LOGFILE="$1"
FileDate=`date +%d%m%Y`
OUTFILE=$LOGFILE.$FileDate.gz

#Rotate File

cat $LOGFILE | gzip -9 > $OUTFILE && > $LOGFILE
#
a bit rough and ready but it does the job

Code tags added for readability --- Perderabo

Last edited by Perderabo; 06-19-2003 at 08:53 AM..
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 08:13 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