LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2010, 03:16 AM   #16
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405

Hi,

About sed's -i option:

Quote:
-i[SUFFIX]
--in-place[=SUFFIX]
This option specifies that files are to be edited in-place. GNU sed does this by creating a temporary file and sending output to this file rather than to the standard output.1.
So it will break the pipe!

evo2 has a good point in post #6. Why can't you wait?
 
Old 03-02-2010, 03:18 AM   #17
karthi_27
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
If you write line by line to the file then just omit the first line which is given by the process write the remaining lines.
 
Old 03-02-2010, 03:19 AM   #18
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Now thats me really confused !!
Code:
A question: Can you not wait until the process has finished writing to the file?
What it exactly means?
 
Old 03-02-2010, 03:29 AM   #19
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

At a certain point your program (the one that writes to the logfile) stops. Once that happens you can edit the logfile without having to worry about the program writing to it.
 
Old 03-02-2010, 03:29 AM   #20
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
At some point the process will stop or be killed: eg. when you shut down your machine, or when the logs are rotated.

Evo2.
 
Old 03-02-2010, 03:40 AM   #21
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
The Issue is I can't wait for that.
Let me elaborate. There is some junk character being added looks like ^@^@.......which fills up at first line only consuming more and more size..that makes upto 500-700MB size(surprisingly).So That makes my logs over loaded. Once i delete the first line then it freed 500-700 MB. Donno th reason why it does show.
but All I temporarily need to delete the first line.
So Cant wait..
Any Suggestion?
 
Old 03-02-2010, 03:44 AM   #22
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Is there any method I can include the sed script at postrotate directive in logrotate.conf?
Anyone who can help me with what postrotate can do ?
 
Old 03-02-2010, 03:47 AM   #23
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

To my knowledge there isn't a way to do this (lets hope I'm wrong about this, but I doubt it).

I would suggest, if at all possible, to have a look at the program that generates the logfile and make sure (add some code) the first line (the one with 'junk') isn't put in the logfile but discarded.

Hope this helps.

PS: Maybe your idea about logrotate could work. I'm not too familiar with it so maybe others can assist with that.

Last edited by druuna; 03-02-2010 at 03:49 AM. Reason: Added text after extra post OP.
 
Old 03-02-2010, 05:36 AM   #24
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
I tried addding this way:
Code:
#!/bin/bash
> any_temp_file
cp fix.log any_temp_file
sed -i 1D any_temp_file
cat any_temp_file > fix.log
Any idea if this works !!!
 
Old 03-02-2010, 05:38 AM   #25
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
I think the best thing to do here is work out why you are getting that first line of rubbish in the log file. What program is it?

Evo2.
 
Old 03-02-2010, 05:56 AM   #26
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Quote:
Originally Posted by your_shadow03 View Post
I tried addding this way:
Code:
#!/bin/bash
> any_temp_file
cp fix.log any_temp_file
sed -i 1D any_temp_file
cat any_temp_file > fix.log
Any idea if this works !!!
Strickly speaking: No, it won't (you will probably lose some logged data).

But.....

Depending on the frequency of the logging it _might_ work. If nothing is logged while you run the above script it will work, if on the other hand the program does log one or more entries while you run the script, those entries will not show up in the log.

Hope this helps.
 
Old 03-02-2010, 06:38 AM   #27
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
I have pasted run.sh above. Anyone who have hands on Jboss and could solve the issue.
 
Old 03-02-2010, 06:40 AM   #28
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
1. Give me the output of file <log_filename>.
2. Who is writitng this log. (Any java code) ?

This seems to me some kind of binary data been written in to your log file (A mix of ascii and binary I guess). The best way is to identify the Root cause.

Last edited by PMP; 03-02-2010 at 06:43 AM.
 
Old 03-02-2010, 06:59 AM   #29
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Code:
file testfile.log

testfile: data
Code:
-rw-r--r--  1 weadmin admingrp    3922 Mar  2 06:56 testfile.log
 
Old 03-02-2010, 07:02 AM   #30
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@your_shadow03: This is a binary formatted file, _not_ a text file.

You still haven't mentioned what program creates/writes to this log file, but it is done in a binary format.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting: parsing a text file character-by-character Completely Clueless Programming 13 08-12-2009 09:07 AM
Adding date and time to a log file ltodd2 Linux - General 2 12-17-2008 10:05 AM
Adding the character "#" in a file using sed kushalkoolwal Programming 4 07-11-2008 02:59 PM
incorrect character for the log file treotan Red Hat 1 12-05-2005 09:21 PM
access.log (squid) file, adding Logins mizard Linux - Networking 4 09-27-2005 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration