I have these 2 scripts, one is writing to the file:
#!/usr/bin/env bash
while true; do
sleep 1;
echo "$(uuidgen)" >> /tmp/cprev.stdout.log
done;
the other is reading the last 10 lines and overwriting the file with those 10 lines:
#!/usr/bin/env bash
while true; do
sleep 5;
inotifywait -e modify /tmp/cprev.stdout.log | tail /tmp/cprev.stdout.log > /tmp/cprev.stdout.log
done;
for some reason the tail command is truncating the file - what I want to do is write to the file only when the tail command finishes getting all 10 lines from the file, how can I do that?
what actually happens:
- tail truncates file
- tail reads 0 lines
but what I want to do:
- tail reads 10 lines
- tail truncates files
- tail writes 10 lines from above
how can I do that?
tail
isn't writing to the file, the shell is. And the shell truncates it beforetail
gets a chance to read anything – Fox Mar 26 '20 at 01:03