leading null characters produced in script...
- From: "Avalon1178" <Avalon1178@xxxxxxx>
- Date: 29 Oct 2006 22:54:56 -0800
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
Once the $logFile reaches 5000 bytes, it copies it to $logFile.arch and
the other script will continue to populate $logFile once more. When
$logFile once again reaches 5000 bytes, the archiving is triggered.
The problem is, when $logFile is written by this other script the
second time, a bunch of leading nulls are created...and its usually so
long that it triggers the archiving prematurely. (When I do a 'od -h
logFile | less' on the archived log, I basically see hex chars of 0000
0000 * until the first non-null character)
Here is how the other script is generating the $logFile:
....
../otherScript >$logFile 2>&1 &
....
Is there anything I'm doing wrong? Has anyone encountered seeing
leading null characters? If there's no way in getting around this,
what is the best way (preferably in bash) to get rid of these leading
null characters?
Thanks.
Avalon1178
.
- Follow-Ups:
- Re: leading null characters produced in script...
- From: Unruh
- Re: leading null characters produced in script...
- From: Paul Colquhoun
- Re: leading null characters produced in script...
- From: Chris F.A. Johnson
- Re: leading null characters produced in script...
- From: Robert Hull
- Re: leading null characters produced in script...
- Prev by Date: Re: dd and image files
- Next by Date: Re: Which Distribution for VMWare
- Previous by thread: Re: Which Distribution for VMWare
- Next by thread: Re: leading null characters produced in script...
- Index(es):
Relevant Pages
|