Solved

Emptied log file is not working now

Posted on 2004-09-07
6
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

738 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