Operating System - HP-UX
1833757 Members
3000 Online
110063 Solutions
New Discussion

Re: create e.g. a logfile which is not increasing in size

 
SOLVED
Go to solution
Roger Hotz
Occasional Contributor

create e.g. a logfile which is not increasing in size

Dear all

Does anyone know how to create a file which
e.g. has a max size of 100MB and is not increasing if data is written to it. Would be
helpful for logfiles which should not grow more
than a defined size.

Thanks for any help
Roger
Never give up
4 REPLIES 4
Rita C Workman
Honored Contributor

Re: create e.g. a logfile which is not increasing in size

Well, , I believe you can use ulimit to limit the file size of a process...

Check manpage ulimit


/rcw
Bruce Regittko_1
Esteemed Contributor
Solution

Re: create e.g. a logfile which is not increasing in size

Hi,

If you want the file to continuously get updated, yet not grow beyond a certain size, I'm not sure ulimit is best. I think ulimit will just stop writing to the file after it grows too large. See the man page for sh-posix and search for ulimit to find out.

Anyway, attached is a simple (that is, crude and inefficient) script that will trim a file below a certain size. Drop it into a crontab and you will never have to worry about it again :).

--Bruce
www.stratech.com/training
Steffi Jones_1
Esteemed Contributor

Re: create e.g. a logfile which is not increasing in size

Hi Roger,

if you have an idea how fast the file grows you could actually setup a cronjob where the file will be renamed to log.1 or similiar and a new one will be touched.

Logfiles will always grow and some pretty fast, so it is up to you to determine what timeframe you need to empty the files.

Hope that helps a bit,

Steffi Jones
Tim Malnati
Honored Contributor

Re: create e.g. a logfile which is not increasing in size

As an alternative you may want to look at the logrotate utility. Although it does not directly limit logfile size it has a bunch of goodies that allow you to setup automatic rotation, archiving, compression, truncation, email to specified users, etc. It's PD software and it has been ported to HPUX at http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5