Log rotation issue with script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log rotation issue with script
# 1  
Old 11-17-2010
Log rotation issue with script

I have application which to the heavy stdout and I have diverted the stdout to log file.

this log file is writing very heavily and we have a script which rotates the logs.
logic for rotation is smthing like
cp logfile logfile.1
cat /dev/null > logfile

this logic was working fine till we had lesser load coming in logfile but Now there is much stdout going on and after doing a
cat /dev/null > logfile

logfile becomes of size 0 but again shows the same size as was it before.


so what I'm having is
logfile 1GB
after rotation
logfile.1 1GB
logfile 1GB & still appending the data.


I see the FD 1 for the log write is showing the same size as of the file and not coming down.

can you see any issue with this kind of log rotation why it is breaking on heavy IO ( my assumption is that FD 1 is still in blocking mode )
and any suggestion how it can be solved by scripting or othere logic/commands.


Thanks..
Navin
# 2  
Old 11-17-2010
Yes this is a common issues, if a process is appending to the log when you truncate the applications file pointer is still at the end of the file. All sorts of weird things can happen (eg file shows 0 size from commands like ls but application still writes to the old file and uses up space on your filesystem).

Quite a few programs support kill with a HUP signal to get them to rotate their own log files (check the manual or doco for you app). If it dosn't have any built-in log rotate support, your only choice is to stop/suspend the application rotate logs and restart.
# 3  
Old 11-18-2010
is there any other way to get this work around.

I know that same issue happens in Apache logs but Apache overcomes it with piped logging.

What exactly is that, if it is a use of pipes to get the data move around. can that be simulated here.

application where these logs are generating is a live system and I cant stop/suspend that.

any idea would be helpful.

Thanks
Navin
# 4  
Old 11-18-2010
The apache program supports redirecting it's logfile output via a standard unix pipe to any command you like. Apache ships with the logrotate command that basically keeps a timer and after a certain amount of time (or bytes written) it closes it's output file and starts a new one.

Talking about pipes, another idea might be to replace the logfile with a named pipe see this Redhat Page for details. This looks a bit tricky and is likley to introduce a whole new set of issues.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log rotation script

I have an application that rotate its log once it reaches 100mb and it keeps a total of 24 logs. I am trying to write a script to run daily to tar up the previous day logs files and move them to a different directory. here is a long listing of the logs in the directory: -rw-r--r-- 1 user1 ... (6 Replies)
Discussion started by: e_mikey_2000
6 Replies

2. Solaris

Log rotation

Hi All! I seem to have a problem with log rotation, unless I am doing something wrong, I have type the following command for testing purposes to see if the -s option works but he did not: logadm -w /var/adm/messages -C 8 -c -s 512k -t '/var/adm/messages.$n' -z 1 the file is now at this... (7 Replies)
Discussion started by: fretagi
7 Replies

3. UNIX for Dummies Questions & Answers

Log Rotation

Hi Guys, Good morning, I just want to know and collect ideas on this one. Regarding rotation of logs as I've observed it's not consistently functioning. I have a server with 8 Partitions, each partition has a dedicated directory for the logs that is needed and I set it every 5mins (300secs) the... (1 Reply)
Discussion started by: rymnd_12345
1 Replies

4. Solaris

Log rotation, twice

hi folk, need advise regarding the log rotation, i have the logadm set at 30 2 * * * /usr/sbin/logadm so it supposed to rotate once per day, but now it rotated twice! but someone my log will rotate at 2:30 AM, but then another 2 hours later, it creates a new and rotate a new log again,... (2 Replies)
Discussion started by: dehetoxic
2 Replies

5. Solaris

Log Rotation of Catalina.out

Hi, Recently i received a request to rotate logs of catalina.out (tomcat). The file size was about 807 MB. I used logadm to truncate the log ( -c ) and zip (-z 0) it. Everything worked fine, catalina.out.0.gz was created (22 MB) and the size of original catalina.out became 0kb. After... (2 Replies)
Discussion started by: Mack1982
2 Replies

6. Web Development

Mod_Jk Log rotation

Hi , I have cronolog (http://cronolog.org/) setup to rotate both my error and access logs, but how can I use it to rotate my mod_jk.log file. I tried different things but cant get it to work. I want to end up where all three files will be rotated daily in YYYY/MM/DD folder format. thanks (0 Replies)
Discussion started by: new2learn09
0 Replies

7. Shell Programming and Scripting

Log rotation script

I have the below script to help with disk space cleanup that finds logs older than a specified number of days (say 10 days). I need it to grab "active" logs as well. Problem is an "active log" will not get archived unless I put in 0 days which I don't want to do, I need to leave the past 10 days,... (2 Replies)
Discussion started by: theninja
2 Replies

8. Shell Programming and Scripting

log rotation

Hello all. Due to some reason I can not use HUP to rotate needed log files. So I use the standard method: cp $file $file.1 cat /dev/null > $file But if Java application in this time writing the output to $file, in the beginning of it appears many "^@^@^@^@^@^@". How to avoid it? Or how... (6 Replies)
Discussion started by: mirusnet
6 Replies

9. HP-UX

Log rotation on HP-UX

Can anyone post a sample log rotate and archive configuration on HP-UX? I really don't know how to do that... :( (3 Replies)
Discussion started by: untamed
3 Replies

10. Shell Programming and Scripting

Log Rotation Tool/Script

Hello all Does anyone has an intersting script or a good freeware tool for log rotation that is good for Unix and Linux as well ? My thanks in advance (4 Replies)
Discussion started by: yelalouf
4 Replies
Login or Register to Ask a Question