Re: leading null characters produced in script...



Paul Colquhoun <postmaster@xxxxxxxxxxxxxxxxxxxx> writes:

On 29 Oct 2006 22:54:56 -0800, Avalon1178 <Avalon1178@xxxxxxx> wrote:
| Hello,
|
| I'm trying to write a small script using bash that essentially archives
| logs to prevent logs from getting too big and take up drive space. The
| way I do it, when a log file reaches a certain size, I have an external
| script that copies that log file to another file, truncates to 0 length
| the original log file, and let the the other script that generates the
| log continues on. The problem I'm having is I'm getting leading null
| characters at the beginning of the new log, which sometimes takes too
| many bytes which triggers my log archiver prematurely.
|
| For example, here's is my (simplified) log archiver script written in
| bash:
|
| while [1]; do
| if [ -a $logFile ]; then
| logSize=$(stat -c%s $logFile);
| if [ $logSize -ge 5000 ]; then
| cp $logFile $logFile.arch
| cat /dev/null >$logFile
| fi
| fi
| done


I think you need 'cp /dev/null $logFile' instead of 'cat'.

iAll you need is
>$logfile


--
Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol
Asking for technical help in newsgroups? Read this first:
http://catb.org/~esr/faqs/smart-questions.html#intro
.



Relevant Pages

  • Re: leading null characters produced in script...
    ... | I'm trying to write a small script using bash that essentially archives ... | way I do it, when a log file reaches a certain size, I have an external ... | many bytes which triggers my log archiver prematurely. ...
    (comp.os.linux.misc)
  • leading null characters produced in script...
    ... I'm trying to write a small script using bash that essentially archives ... many bytes which triggers my log archiver prematurely. ... cp $logFile $logFile.arch ...
    (comp.os.linux.misc)
  • Re: leading null characters produced in script...
    ... I'm trying to write a small script using bash that essentially archives ... way I do it, when a log file reaches a certain size, I have an external ... many bytes which triggers my log archiver prematurely. ... cp $logFile $logFile.arch ...
    (comp.os.linux.misc)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > 1) They were out of context quotes, as the quotes came with no context. ... embed cpu instructions within a DOS/Windows batch script. ... that this also is possible with bash scripts. ... statement "It can execute the .com file as easily as a command.com ...
    (alt.lang.asm)
  • Re: [opensuse] Editting PATH variable
    ... SuSEconfig script ... ... not knowing what you options you used to install ... If your unfamiliar with Bash a good book is 'Learning the Bash Shell' by ... For Java use editing the PATH variable is NOT required... ...
    (SuSE)