1753681 Members
5739 Online
108799 Solutions
New Discussion юеВ

Trim Log Files.

 
SOLVED
Go to solution
Global Service Desk
Frequent Advisor

Trim Log Files.

Hi,

Can anyone please let me know how to trim the log files (like Cron, syslod etc.) when the process is active.

I had followed the following but it didnt append the files.

1. Stop(pause) the process usind #kill -STOP .
2. Rename the file cron log file
#mv log log.old
3. Touched the new file with same file permissions.

#touch log
4. Continue the process #kill -CONT .

after doing this the cron process didnt append the log file.

i had to manually restart the service then it started writing to log file.

I had this probelm always with few log files.. can anyone tell me the best way to do it.

Many thanks in advance !!

Regards
Govinda.
12 REPLIES 12
Jaime Bolanos Rojas.
Honored Contributor

Re: Trim Log Files.

Hi,

I am sure this thread will help you out,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1033864

Regards,

Jaime.
Work hard when the need comes out.
James R. Ferguson
Acclaimed Contributor

Re: Trim Log Files.

Hi Govinda:

If you want to empty the entire file, simply do, for example:

# cat /dev/null > /var/adm/syslog/syslog.log

If you want to preserve a copy of 'syslog' and open a new one, one simple way is to do:

# /sbin/init.d/syslogd stop
# /sbin/init.d/syslogd start

This action creates '/var/adm/syslog/OLDsyslog.log'.

Regards!

...JRF...
Global Service Desk
Frequent Advisor

Re: Trim Log Files.

Hi jamie,

Thanks for the reply, I had look at the thread but it talks about using SAM to trim the logs.

I need to know how we can handle the running process using command prompt while trimming the activity logs.

many Thanks!!
Govinda.
Global Service Desk
Frequent Advisor

Re: Trim Log Files.

james,

I dont want to stop the process. please let me know if this is possible without stop.

regards
govinda.
Jaime Bolanos Rojas.
Honored Contributor

Re: Trim Log Files.

Hi again!

I do not know if Mattew will be able to see your other post on time, but in the mean time, take a look at this utility,

http://hpux.ee.ualberta.ca/hppd/hpux/Sysadmin/logrotate-2.5/

Very helpful, and it might be able to fit your needs,

Regards,

Jaime.
Work hard when the need comes out.
DCE
Honored Contributor

Re: Trim Log Files.


Rather than moving the original file, copy it with a -p
cp -p file.log filenew.log

thaen cat /dev/null to the original file

cat /dev/null > file.log

this zero out the file without affecting any prgram using it
Victor BERRIDGE
Honored Contributor

Re: Trim Log Files.

Hi,
The only way for not having to restart is, as James mentionned >...
moving the file doesnt work because it will follow the mv rather than writing in a new file...
So the only option is to copy the file AND
and zero the file following James syntax e.g:
# cat /dev/null > /var/adm/syslog/syslog.log

All the best
Victor
Steven E. Protter
Exalted Contributor

Re: Trim Log Files.

Shalom,

Typically, I copy them off to NFS central storage for possible audits and....

> logfile.name

In a cron script.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Bill Hassell
Honored Contributor
Solution

Re: Trim Log Files.

There is no reason to stop the process that is writing to the log file. Just copy and zero as in:

cp -p file_name new_file_name
cat /dev/null > file_name

The processes that are appending to the log file will continue to append to the file which happens to be zero length now. After you have zeroed the file, you may wish to move the copy or at least analyze the file for important data and then compress the file. A very typical method is to shift a series of files, perhaps the last 10 copies so you have a long history. The best technique is to trim logfiles based on size so only the fastest growing files will be regularly trimmed.

The attached script does exactly this function with parameters to control the number of copies and the size to start trimming. Run this script once to setup the copies and perform the first trim. Then add the script to cron to run once a day or once a week. The script does nothing if the files are too small for trimming.


Bill Hassell, sysadmin