?
Solved

Emptied log file is not working now

Posted on 2004-09-07
6
Medium Priority
?
253 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 2

Accepted Solution

by:
Sunjith earned 150 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
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…
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…
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.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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