Solved

Emptied log file is not working now

Posted on 2004-09-07
6
243 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
Comment Utility
0
 
LVL 18

Expert Comment

by:liddler
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Accepted Solution

by:
Sunjith earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now