LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Some character adding up starting of log file? (https://www.linuxquestions.org/questions/linux-newbie-8/some-character-adding-up-starting-of-log-file-792511/)

druuna 03-02-2010 03:16 AM

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?

karthi_27 03-02-2010 03:18 AM

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.

your_shadow03 03-02-2010 03:19 AM

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?

druuna 03-02-2010 03:29 AM

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.

evo2 03-02-2010 03:29 AM

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

Evo2.

your_shadow03 03-02-2010 03:40 AM

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?

your_shadow03 03-02-2010 03:44 AM

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 ?

druuna 03-02-2010 03:47 AM

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.

your_shadow03 03-02-2010 05:36 AM

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 !!!

evo2 03-02-2010 05:38 AM

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.

druuna 03-02-2010 05:56 AM

Hi,

Quote:

Originally Posted by your_shadow03 (Post 3882297)
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.

your_shadow03 03-02-2010 06:38 AM

I have pasted run.sh above. Anyone who have hands on Jboss and could solve the issue.

PMP 03-02-2010 06:40 AM

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.

your_shadow03 03-02-2010 06:59 AM

Code:

file testfile.log

testfile: data

Code:

-rw-r--r--  1 weadmin admingrp    3922 Mar  2 06:56 testfile.log

druuna 03-02-2010 07:02 AM

@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.


All times are GMT -5. The time now is 06:17 PM.