LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 10-19-2004, 01:56 PM   #1
JaBa
LQ Newbie
 
Registered: Oct 2004
Posts: 13

Rep: Reputation: 0
Arrow How to clean up /var/log/messages ?


I am unable to clean up /var/log/messages
Looks like it is locked by some process(es)

I am using Redhat 9.

I tried this:

stopped the syslog service

echo > /var/log/messages

this gives an 'operation not permitted'

echo >> /var/log/messages

is no problem (adding a line to the file).

ls -la gives:

-rw------- 1 root root 170312759 Oct 19 19:42 messages


I would be grateful for any suggestions.

Regards.

JaBa
 
Old 10-19-2004, 01:59 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 33
lsof will show you which process(es) have the file open.
 
Old 10-19-2004, 02:12 PM   #3
JaBa
LQ Newbie
 
Registered: Oct 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Thank you Jim .

lsof gives:
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
syslogd 10574 root 2w REG 9,1 170364313 1880763 /var/log/messages

so i stop the syslog daemon:
service syslog stop

then lsof /var/log/messages gives nothing, so i try again:

echo > /var/log/messages
or
rm /var/log/messages

but i am still unable to remove or clean up
the file /var/log/messages.
 
Old 10-19-2004, 06:21 PM   #4
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 56
Use logrotate to compress and archive old logs from time to time (put it in a cron job and be done with it) and start over with a new empty one. This goes not only for the syslog but other logs as well (mailers, and so on).


Håkan
 
Old 10-21-2004, 05:47 AM   #5
JaBa
LQ Newbie
 
Registered: Oct 2004
Posts: 13

Original Poster
Rep: Reputation: 0
TY Håkan.

I already use logrotate for the log files, everything is running fine there except for /var/log/messages.
 
Old 10-21-2004, 08:13 AM   #6
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,121

Rep: Reputation: 121Reputation: 121
Quote:
Originally posted by JaBa
TY Håkan.

I already use logrotate for the log files, everything is running fine there except for /var/log/messages.
Well, fix your logrotate scripts to include messages, etc..

Its controlled by syslog, so if most of the other files are getting rotated out and writing after syslog is restarted, I see no reason why messages wouldn't work as well.
 
Old 10-29-2004, 02:46 AM   #7
JaBa
LQ Newbie
 
Registered: Oct 2004
Posts: 13

Original Poster
Rep: Reputation: 0
This is my workaround:

I restart Redhat in the 'rescue' mode and mounted the partition (read/write) under /mnt/sysimage, but even then it is not possible to remove the file /var/log/messages (/mnt/sysimage/var/log/messages).

I renamed the log-directory to oldlog and created a new log-dir, rebooted the server and now it is possible to remove the 'new' log file from /var/log/messages, but it is still not possible to remove the file /var/oldlog/messages.

Is this a corrupt file ? Does anyone know how to deal with these files ??
 
Old 10-29-2004, 07:38 AM   #8
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,121

Rep: Reputation: 121Reputation: 121
Quote:
Originally posted by JaBa
This is my workaround:

I restart Redhat in the 'rescue' mode and mounted the partition (read/write) under /mnt/sysimage, but even then it is not possible to remove the file /var/log/messages (/mnt/sysimage/var/log/messages).

I renamed the log-directory to oldlog and created a new log-dir, rebooted the server and now it is possible to remove the 'new' log file from /var/log/messages, but it is still not possible to remove the file /var/oldlog/messages.

Is this a corrupt file ? Does anyone know how to deal with these files ??
I think you took about 10 steps too many and 30 minutes that should have taken you 3 steps and 2 minutes..

Of course messages is going to be locked, its usually gettin written to quite often. What you should have done was stop syslogd, remove file, restart syslogd.

And now if you never want to encounter this problem again, setup and configure logrotate properly, it will do all of this for you.. (even without rebooting your system)
 
Old 10-29-2004, 12:01 PM   #9
JaBa
LQ Newbie
 
Registered: Oct 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by trickykid
I think you took about 10 steps too many and 30 minutes that should have taken you 3 steps and 2 minutes..

Of course messages is going to be locked, its usually gettin written to quite often. What you should have done was stop syslogd, remove file, restart syslogd.

And now if you never want to encounter this problem again, setup and configure logrotate properly, it will do all of this for you.. (even without rebooting your system)


Trickykid:

Thanks for your reply, but:

-i already used logrotate and it did work for about half a year very well (for all log-files).
-i know that you should stop de syslog daemon first, before you can dan anything to the file (messages).

I experienced problems with the file a couple of weeks ago, the other log-files are not having the problem, logrotate works still fine for these.
 
Old 10-29-2004, 12:39 PM   #10
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
Did you check if there were any attributes set for the directory/file?
lsattr
The existence of attributes are often forgot about. They are actually quite handy sometimes.
 
Old 10-30-2004, 12:32 AM   #11
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,402

Rep: Reputation: 212Reputation: 212Reputation: 212
Echo > /var/log/messages (ditto >>) won't clean up anything. The > is a re-direct to send something to /var/log/messages. The clean messages up (I assume you mean to clean out the file and leave an empty file), do this: su to root, then /dev/null > /var/log/messages. This command basically says to overwrite messages with nothing (leaves an empty file).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what does messages suppressed in /var/log/messages mean saavik Linux - Networking 2 05-07-2008 02:31 PM
Redirecting the kernel messages to file other than /var/log/messages jyotika_b83 Linux - General 3 04-28-2005 06:39 PM
From where am i getting error messages to /var/log/messages? prabhuacsp Programming 3 02-16-2005 08:59 AM
From where am i getting error messages to /var/log/messages? prabhuacsp Linux - Networking 1 02-16-2005 12:34 AM
/var/log/messages full of these messages. Should I be concerned? mdavis Linux - Security 5 04-16-2004 10:08 AM


All times are GMT -5. The time now is 03:36 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration