syslog log file sizes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users syslog log file sizes
# 1  
Old 06-18-2003
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  
Old 06-18-2003
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  
Old 06-18-2003
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  
Old 06-19-2003
cheers both I will give this a go
# 5  
Old 06-19-2003
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 09:53 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing file sizes

Hello, I need to compare the size of a file to what it's size was 20min ago. So far my outline script is:ls -ls /home > filesizeafter.txt compare filesizeafter.txt filesizebefore.txt > filesizechange.txt if /home filesizechange.txt > 100 { email root; } ls -ls /home >... (2 Replies)
Discussion started by: chyurdan
2 Replies

2. UNIX Desktop Questions & Answers

Summing file sizes

I was just curious about how to sum the total file size of a certain type of file. For instance: $find . -name "*.aif" will print out the paths to each .aif file. Instead of printing, how could one sum the total space used by all of the aif files? Thanks! Please use code tags (3 Replies)
Discussion started by: Alexander4444
3 Replies

3. Shell Programming and Scripting

Add all file sizes in ls -l

solaris 10 (c shell) need a command or script that will add up all (*.tmp) file sizes in bytes of a single directory, or kbytes, no matter (1 Reply)
Discussion started by: ajp7701
1 Replies

4. UNIX for Dummies Questions & Answers

Checking for file Sizes

Hi , I have some 10 files where i need to check the size of each and every file...if the size of the file is 0...I shud send out an email mentioning which file is actually of 0KB size.. Pls help (13 Replies)
Discussion started by: saggiboy10
13 Replies

5. UNIX for Dummies Questions & Answers

Compare two file sizes.

Hi everyone! I need to compare two file sizes. One of them (size) will be stored in a flat file and the other coming from a listed file. I can now get the first file size using: SIZE=`ls -l $DOCTYPE | awk '{print $5}'` 1. How can I store this value in a flat file? 2. How... (2 Replies)
Discussion started by: mrreds
2 Replies

6. Shell Programming and Scripting

Help with file sizes

I have 2 big files in the size of gb. They are same with respect to content, both are “,” delimited. Now both of them are created by two different processes but has the same logic. The problem is they are differing only in few bytes for e.g one file is 202195751 bytes other is 202195773. So... (2 Replies)
Discussion started by: dsravan
2 Replies

7. UNIX for Dummies Questions & Answers

File sizes -- why do they change?

I just noticed that the copy of a file I made is smaller than the original, although I hardly made any changes to it. Can anyone tell me what determines the size of files? They're all .doc files (saved in NeoOffice). It's really frustrating, because I'm using them to respond to job ads and the... (1 Reply)
Discussion started by: Straitsfan
1 Replies

8. Shell Programming and Scripting

how to compare file sizes

hi ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out1 ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out2 diff out1 out2 i tried this it will work fine and i can see difference but i need a script which should neglect, if the difference b/w files is small and it should display... (5 Replies)
Discussion started by: revenna
5 Replies

9. UNIX for Dummies Questions & Answers

Help on adding file sizes

Hi I need to take a list of files that are defined by an ls -ltr or grep for particular file names - and add up the byte size colum which is field 5 seperated by a space. I tried to do this but I think I am way off: for file in 'ls -ltr | grep 20070916 | nawk -F" " '{temp+=5} END {print... (1 Reply)
Discussion started by: llsmr777
1 Replies

10. Shell Programming and Scripting

compare file sizes

Is there a command that will return the name of the largest file within a directory? If so, can I set the returned filename into a variable? (4 Replies)
Discussion started by: joli
4 Replies
Login or Register to Ask a Question