It's not a secret anymore!
The moose likes Linux / UNIX and the fly likes Log Rotation Issue on Solaris Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Log Rotation Issue on Solaris" Watch "Log Rotation Issue on Solaris" New topic

Log Rotation Issue on Solaris

Chang Iych

Joined: Mar 06, 2006
Posts: 5
I have a log file on Solaris (SunOS <hostname> 5.9 Generic_118558-11 sun4u sparc SUNW,Sun-Fire-V490) that needs to be rotated everyday. I've scheduled a job for this purpose and it looks like this...

cp abc.log abc.log.`date '+%Y-%m-%d'`
: > abc.log

I have a problem here, when I do a less abc.log after the rotation i get all junk characters in the log


However a tail -f abc.log gives me the required output ( the log file is being updated continuously). The size of the log file hasn't changed after the rotation. I tried rotating the log with the following script but that didn't help either..

cp abc.log abc.log.`date '+%Y-%m-%d'`
cat /dev/null > abc.log

Can anybody shed more light on what is happening here.
Thanks in advance..
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I'm using Linux, and don't know how much the systems differ.
The first thing is: There is a file /etc/logrotate.conf which includes scripts from /etc/logrotate.d/*, which seems to be a good idea.

The second idea is schedulers path: Some of them don't have an environment set, and might need absolute paths for programs like cp, cat and date.

Does it work from the shell?
Is a file abc.log.2006-03-05 created?

less might be confused if the file is too small, but it seems it is rather long? should tell you the number of lines.

You could do a

or even a

(backticks are discouraged, but perhaps not on your platform) but perhaps owner and permissions are affekted and not affected, if you use cat.
Brian Wright

Joined: Dec 12, 2005
Posts: 11
I suspect your problem is related to the Great Inode Confusion

cp abc.log abc.log.`date '+%Y-%m-%d'`
: > abc.log

Let's use some sample inode numbers - we'll say abc.log=inode 12345

In the first command, you're copying abc.log, which creates a copy successfully. abc.log.20060324=inode 23456

Your next command attempts to write to the existing abc.log IE it attempts to write to the beginning of abc.log which is inode 12345. Here's where the problem occurs - the program creating this log is still writing it's output to inode 12345 and still has that file open! I'd suggest checking your webserver/whatever program is generating the log and see what are the options for log rotation. Of course, you could always just restart the program nightly...

There are a few funky things you could try to get around this, but I'd suggest caution unless you're really certain what you're doing.
I agree. Here's the link:
subject: Log Rotation Issue on Solaris
It's not a secret anymore!