Solved

Emptied log file is not working now

Posted on 2004-09-07
6
247 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

773 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