Hello all,
I'm trying to find a simple way to append/write to a log, while at the same time keeping it the log trimmed to a reasonable size. I would prefer to not just append files forever, and then have to have a clean up log script. I can't wrap my head around how I would accomplish this gracefully without using some second file as a temporary holder.
Things I've looked at for reference:
I've gone through the advanced scripting guide
http://tldp.org/LDP/abs/html/io-redirection.html
Combined output from two commands: http://serverfault.com/questions/53995/bash-how-to-output-two-commands-to-file
Ideally I would have something like (I know this doesn't work)
(tail-n 1000 foo.log; ./foo.sh) > foo.log
which would keep the last 1000 lines from my on going log and then append my new output for the current run of foo.sh.
I can't think of a way to use the append redirect >> and limit the original file without wrapping the call to foo.sh in some other bar.sh
head -n 1000 foo.log > tmp.log
mv tmp.log foo.log
./foo.sh >> foo.log
This just seems kludgey.
Perhaps my answer is to have foo.sh not rely on STDOUT as a place to send log messages, but rather opens the file directly.
Thanks for any input.