Operating System - HP-UX
1833873 Members
2130 Online
110063 Solutions
New Discussion

log rotation by command >

 
SOLVED
Go to solution
Shivkumar
Super Advisor

log rotation by command >

Why most of the log files gets rotated using the command "> logfilename" ?

Thanks,
Shiv
8 REPLIES 8
Peter Godron
Honored Contributor

Re: log rotation by command >

Shiv,
the > logfilename is a redirect of output command.
Please clarify your question.
Joseph Loo
Honored Contributor

Re: log rotation by command >

hi,

that do not rotate the log file (or any file for that matter). it will "null" or empty the file, i.e. create a zero-length file.

# man null
for more info.

regards.
what you do not see does not mean you should not believe
Vibhor Kumar Agarwal
Esteemed Contributor

Re: log rotation by command >

I think he is talking about using the same name of logfiles after sometimes.

Well,
With time logfiles become very large in size and slowly they can occupy your whole filesystem.

So its a good convention after sometime you start using the same logfile.
Vibhor Kumar Agarwal
Leif Halvarsson_2
Honored Contributor
Solution

Re: log rotation by command >

Hi,
"> logfilename" is truncating, not rotating (all previous information is lost).

Some logfiles is "rotated" (old file renamed and a new created) automatic at reboot or login (e.g. the syslog.log or the $HOME/.dt/startlog).
Victor BERRIDGE
Honored Contributor

Re: log rotation by command >

Hi,
Do not get confused as Leif mentionned > will overwrite what was there previously to append to you would need >>

Now as for rotating logs you would use your own custum scripts or tool like logrotate:
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/

All the best
Victor
Simon Hargrave
Honored Contributor

Re: log rotation by command >

The full procedure to "rotate" a logfile is something like: -

cp /var/adm/syslog/syslog.log /var/adm/syslog/syslog.log.`date +%d%m%y`
> /var/adm/syslog/syslog.log

This copies the contents of the file to a dated file then empties the existing log. You would probably also compress the dated log.

The reason you can't just move the file is that because the file is open (by the syslog daemon in this case), the file even though renamed still gets written to.

A process when opening a file attaches to the inode (underlying pointer), so when you rename a file the inode remains the same.
Vibhor Kumar Agarwal
Esteemed Contributor

Re: log rotation by command >

I don't think this will works.

I have a file open for writing then simply doing a cat terminates that process.

Here you truncating the whole file which is still open.
Vibhor Kumar Agarwal
Devender Khatana
Honored Contributor

Re: log rotation by command >

Hi,

--->I have a file open for writing then simply doing a cat terminates that process.

Not in every case. Sometimes even when you remove the file , the process will keep on. Also it will not release the blocks occupied by such file and the process needs to be terminated manually if you need to get the free space.

>logfilename works for any file you need to null out and not only for the logfiles. This redirects the null to the content of the file, inturn making it a zero byte file.

The samething will be achived by 0>filename.


HTH,
Devender
Impossible itself mentions "I m possible"