Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a setup where a db server shares some directories through nfs with a cluster of websers.

One of this directories is the apache log one, so webservers all write to a unified db server access.log.

I'm trying to clear this file with cat /dev/null > access.log, but the command does nothing.

Do you know how can I clear it without removing it? Thanks in advance, Simon.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Let me say first of all that having all web servers write to a unique log file via NFS is a very bad idea, all kind of problems arise, like the one you're facing right now.

In order to be able to empty the file you'll need to first of all rename it, then proceed to restart every single apache instance until the file is not open by any process, then and only then you'll be able to delete it.

If I may suggest an alternative, you can achieve the same thing by having apache write to your local log and then use syslog-ng to send the log to a remote machine where all the logs are collected under one, it's a way more resiliant solution, I've documented the howto in this question here

share|improve this answer
add comment

Use touch /path/filename.log to create a file with a zero byte size

share|improve this answer
    
He doesn't want to create a new file, simply clear an existing one... –  Chopper3 Feb 10 '11 at 11:01
    
touch will not erase files, it just creates them if they don't exist already. –  Chris S Feb 10 '11 at 13:27
    
yeah, but access.log exists at the moment, and deleting it and touching a new onw won't work (already tried). –  Simon Feb 10 '11 at 13:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.