• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Log Rotation Issue on Solaris

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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..
Chang
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
this is supposed to be a surprise, but it smells like a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic