Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managing logs that grow large 3

Status
Not open for further replies.

m2001331

Technical User
May 29, 2002
73
MY
Hi,
How can I write a script to manage logs that is beinjg generated by some programs in my system.
I am on a Linux server, I have some grows that grows with every transaction and i have to leave this programs running hence the log size growth.i'd like to know how i can have a script that will backup the log - say test.log and then gzip and move it to another location.
eg. log name = /abc/test.log
backup log name = /abc/test070105.log
gzip-ed and moved to new location = /dce/test070105.log.gzip.
Please advise how can i go about doing this?
thank you.
 
man logrotate, and /etc/logrotate.d/ for some examples.
 
hi , i am looking for sample scripts that i can use to do this. The man logrotate , i think reuses the log? not familiar with linux, been a windows user all this while.
thanks.
 
logrotate will gzip the log and create a new log file.
log files don't get overwritten, so after a while you may have something like sshd.log.gz.0 all the way up to sshd.log.gz.15 ...

Or change your logging daemon. Metalog can do all that for you , if I recall correctly.

-Haben sie fosforos?
-No tiengo caballero, but I have un briquet.
 
is it able to do this for non system generated log files - non root user's log files?>
what is the syntax like to use it?
thanks
 
You can use it for any log files (any files, really). "man logrotate" will show you the syntax.

Simply putting a configuration file in /etc/logrotate.d will activate it, as /etc/logrotate.conf includes all files in that directory. (Remember this, and don't save .bak versions of your config files there).

A sample web log rotation:
/var/log/httpd/*_log {
compress
dateext
maxage 365
rotate 99
size +4M
missingok
notifempty
sharedscripts
prerotate
/etc/cron.daily/webstats
endscript
postrotate
/etc/init.d/httpd graceful
endscript
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top