setting max log file size...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting setting max log file size...
# 1  
Old 03-31-2002
setting max log file size...

Hello all!

I have found a new home, this place is great!

I have been searching for days to find a way to set a max size for a log.txt file using a cron job exicuting a shell script. Is it possible for a script to remove older entries in a log file to maintain a limited file size? If so, how?

Thanks very much for you time!
# 2  
Old 03-31-2002
It would be nice if unix supported circular files. On old HP3000, I could build a file of desired size, specify cir attribute, and output to the file would be circular.

The following downsizes log.txt back to 800 lines after it hits 1200 lines, but you could use "wc -c" to control on number of characters instead. I use tail +nnn logic because tail -nnn will go back only so far.

Of course, do this when the file is not in use.
Code:
#!/bin/sh

wc -l log.txt | read lcnt other

if [ $lcnt -gt 1200 ] ; then
   ((start=$lcnt-799))
   echo 'downsizing ...'
   tail +$start log.txt > log.txtN
   mv log.txtN log.txt
fi

exit 0

Jimbo
# 3  
Old 03-31-2002
Thanks very much Jimbo!

Is there no way of doing this via file size, not number of lines?

Also, how would go about editing the log files for multiple users from root?

I have really done a lot of searching with no luck. I am really glad I found this place!

Thanks again!
# 4  
Old 03-31-2002
What about a crontab to find large log files and erase them?

I am currently using the following crontab to email me when a log file is larger then 2000:

00 00 * * * /usr/bin/find /home/user/www/cgi -type f -name "log.txt" -size +2000 | mail me@here.com -s "Log Finder"

How do I use cp /dev/null or something in the crontab to just erase(not delete) the logs instead of emailing me?

Thanks again!
# 5  
Old 04-01-2002
My script above is to get rid of the older portion of large files while maintaining the newer portion. It could downsize when a file hits a certain number of characters instead of number of lines. Both the wc and tail commands support number of characters.

But if you just want to empty the large files, that's a lot easier. The easiest way to empty a file and leave it there is:

> myfile

and if running as root, ownership and file permissions will remain unchanged. Normally you can use the -exec parameter on a find command to do some command on each qualifying file, such as:

find . -name "test*" -exec rm {} \;

but I was not able to get the redirection command above to work in this context. But there are several ways to feed the filenames, such as piping into xargs. I would suggest the following, but test it first by replacing the "> $fn" with "echo $fn":
Code:
#!/bin/sh
for fn in `find . -size 2000`
do
> $fn
done
exit 0

Jimbo
# 6  
Old 04-01-2002
FreeBSD has a cool program to handle this called newsyslog. It's real easy to run it on other unix versions. You can get it via ftp from here.

And don't let the name fool you, it's not just for syslog files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Clamd max file size Solaris 10

Hi, I've compiled a 64-bit version of ClamAV 0.98.7 on my Solaris 10 SPARC server. I have a selection of files all containing the eicar signature but clamd is only picking up the signature in the files <2GB. I have the following set in clamd.conf, to remove file size checking: MaxScanSize 0... (4 Replies)
Discussion started by: Troutfest
4 Replies

2. AIX

Profile Max CPU Setting

I have a system with the following settings: min:0.10 Assigned: 2.0 Max: 6.0 Partition is uncapped weight is 128. I would like to know if even if this is uncapped, is the max it can use 6? The actual pool has 16. I remember reading about this somewhere but I don't remember can anyone... (3 Replies)
Discussion started by: techy1
3 Replies

3. UNIX for Dummies Questions & Answers

Restrict Max file size

Hello All, I am working on an issue, where I need to check the max file size of a file. If the file size exceeds 2 GB, then I need to generate an error message. Since the file system does not allow a file to be created larger than 2 GB, I am planning to use named pipes & AWK file to acheive my... (6 Replies)
Discussion started by: puru2121
6 Replies

4. Solaris

File size setting

There is a file in my Unix Server whose size will be constant. But every day when the sheduled jobs run in the server, that file gets updated but the size does not change. Upon doing file filename It is dispalyed as a binary file. Can anyone please explain how that file is created. How is... (3 Replies)
Discussion started by: exterminator
3 Replies

5. SuSE

Setting the max open files value

I'm trying to set the open files value to 4000 on a SLES 9 system. Current values:ulimit -n 1024 I can set it using this:ulimit -n 4000 ulimit -n 4000 But this obviously sets it only for the shell session where I run the command to set it. I want to set this to 4000 for all time. ... (3 Replies)
Discussion started by: blowtorch
3 Replies

6. UNIX for Dummies Questions & Answers

MAX file size limited to 2GB

Hi All, We are running HP rp7400 box with hpux 11iv1. Recently, we changed 3 kernel parameters a) msgseg from 32560 to 32767 b) msgmnb from 65536 to 65535 c) msgssz from 128 to 256 Then we noticed that all application debug file size increase upto 2GB then it stops. So far we did not... (1 Reply)
Discussion started by: mhbd
1 Replies

7. UNIX for Advanced & Expert Users

Max. file size

i want to know what is the maximum file size supported by linux with ext3 file system. (1 Reply)
Discussion started by: nagalenoj
1 Replies

8. Solaris

max. size of file

I wants to ask that what is the max size of file that we can create in the unix file system. (2 Replies)
Discussion started by: sameerghogre
2 Replies

9. UNIX for Advanced & Expert Users

How to determine the max file size

Does anyone know a way to determine the maximum filesize on a file system on Solaris, HP-UX, AIX, Linux, and OSF1 using the command line? TIA (2 Replies)
Discussion started by: dknight
2 Replies

10. Programming

Max file size can't exceed 2 GB

We have Sun OS 5.9 we are doing a backup process (ProC program) that uses the function... fprintf(fp,"%s;%s;%s;%s;%s;%ld;%ld;%ld;%ld;%s;%s;%s;%d;%s;%s;%s;%ld;%s;%s;%s;%ld;%ld;%s;%ld;%s;%ld;%s;%s;%c%c",x_contrno, x_subno, x_b_subno,x_transdate,x_last_traffic_date,BillAmt_s, x_billamount_int,... (10 Replies)
Discussion started by: atiato
10 Replies
Login or Register to Ask a Question