Solved

Emptied log file is not working now

Posted on 2004-09-07
6
249 Views
Last Modified: 2010-04-20
I'm quite new to linux, and was wondering what is the best way to empty / archive a log file.

The file in question is /var/log/messages

I tried:

mv /var/log/messages /var/log/messages.archive.07-09-2004
touch /var/log/messages    to create new empty log file

but now nothing is being written to the logfile! How can I fix this and how should I have done it?

Thanks.
0
Comment
Question by:mcwalters
6 Comments
 
LVL 18

Expert Comment

by:liddler
ID: 11996864
0
 
LVL 18

Expert Comment

by:liddler
ID: 11997363
mcwalters
post a 0 pt Q in Community Support asking for a refund & delete of this Q, as it was answered in the other thread
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12003627
I have an answer to your question:
if the logfile is still open and you rename it or move it, the writing/appending still happens to the renamed file.
If you delete it or truncate it, the writing goes on to the file, virtual or on offset.
That's why the new logfile is ignored.
The right way is to have the writer reopen a new logfile or ....
... if loggings are not too frequent, the file may be opened-appended-closed on every logging.
Nowadays this approach is relatively cheap.

;JOOP!
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 2

Accepted Solution

by:
Sunjith earned 50 total points
ID: 12007436
cat /dev/null > /var/log/messages
The above command will empty your log file quick and easy :-)
If you want to archive it, archive it before you empty:
Using bzip2:
bzip2 -k /var/log/messages
Or if you are using gzip:
gzip -c /var/log/messages > /var/log/messages.gz
Or if you want to use zip:
zip /var/log/messages.zip /var/log/messages
0
 

Author Comment

by:mcwalters
ID: 12007538
Thanks for the help guys.

I awarded the points already in another thread:
http://www.experts-exchange.com/Operating_Systems/Linux/Linux_Administration/Q_21121466.html

but will give these to you Sunjith as this will help me too :-)
0
 
LVL 2

Expert Comment

by:Sunjith
ID: 12007911
Thank you :-)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to enable sync between two yum repo? 1 52
lunix and unix command 21 111
Samba Question 11 103
How do I setup Wordpress to use Master / Slave MySQL database setup? 4 86
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question