Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a log file

Status
Not open for further replies.

bluedragon2

IS-IT--Management
Jan 24, 2003
2,642
US
I am trying to clear a log file that is ~45 meg by doing:

cat /dev/null > logfile.log

When I do this, it takes the file to 0 bytes then back to the original size. If I do a more on the file, it just has blank lines.

On another server, I do this and it remains at 0 bytes.

What could be causing this?

Thanks

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
You can just use the command >filename to empty it.
 
does not work as well

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
There isnt something filling it up (with blank lines) as fast as you are emptying it, is there?
 
No, the application is putting real data at the end of the file ~10-15K per minute.

Doing the cat on the file just deleted the data and left blank lines.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Hmm.... is your /dev/null really a /dev/null?

...shooting in the dark at this point as cat /dev/null > /some/log.file should zero it out.
 
Yes, if I do it on another file, it works fine. Must be something with the application. This is not a big deal, just wonder why it is happening only on one server.

Thanks for your suggestions.



[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
It all depends on the application that is writing to the log file. Unfortunately some applications write to a specific offset in the log file, so even if you flatten the log file like you have been, it will write the next line of output to the offset where it thinks the end of the file was.

Check the application's documentation to see if there is a way you can tell it to switch log files. Some applications will reopen their log files if you send them a SIGHUP. Some will require a restart.

You may find that the log file is now a 'sparse' file... i.e. ls says the file size is 45MB, however if you do a du on it, the size will be much smaller. So you may have achieved what you wanted anyway (i.e. saved some disk space).

Annihilannic.
 
It all depends on the application that is writing to the log file. Unfortunately some applications write to a specific offset in the log file, so even if you flatten the log file like you have been, it will write the next line of output to the offset where it thinks the end of the file was.

Check the application's documentation to see if there is a way you can tell it to switch log files. Some applications will reopen their log files if you send them a SIGHUP. Some will require a restart.

You may find that the log file is now a 'sparse' file... i.e. ls says the file size is 45MB, however if you do a du on it, the size will be much smaller. So you may have achieved what you wanted anyway (i.e. saved some disk space).

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top