Shell Scripts and Large Files
Categories: [ IT | TV/Leffakone ]
while [ $(stat -c %s $filename) -gt $last_size ] do last_size=$(stat -c %s $filename) sleep 1 done
I then noticed that all recordings exceeding one hour (there aren't that many,
that's why it took so long to notice it) where cut in two even though the
picture doesn't show hints of bad reception. More peculiar, the size of the
first part is slightly over 2 GB in size (therefore the problem is not
related to a 2 GB size limit, right?). An experiment conducted yesterday show
that it actually is: the test
program (used here in its |[| form) handling
the -gt
comparison actually doesn't like values greater that 2ˆ31, which
caused the loop to be interrupted and the recording to be split into two
parts.
The solution is then (for Bash at least) to use the following syntax:
while [[ `stat -c %s $filename` -gt $last_size ]]which seems to be working with values greater than 2ˆ31 (and than 2ˆ32, I just checked).
I noticed that with the old Bash 2.05 running on Leffakone, the [[ form is also afflicted by the 2^31 bug (Bash 3.2 works correctly in that respect, though). The solution was to use an external perl script for watching the file grow.