-1

I'm rewriting some 20+ year old Unix scripts and I want the output to go to the screen and a file. I know this is possible with tee. Is there a similar command that stacks new lines on top, at the beginning of a file? I'd like the file to be output in reverse chronological order.

The script output will redirect to a WWW folder. For remotely viewing the output, I want to F5 in a browser and have new lines at the top of the browser window. I'll recycle the file (cp log log_$(date '+%Y%m%d') && cp /dev/null log) everyday to keep it from growing too large.

I was hoping tee had a complimentary utility like cat has with tac, but alas no luck.

user38537
  • 693

1 Answers1

0

To print to STDOUT and insert newlines at the beginning of your log file you'll have to rewrite it completely each time that could be really memory consuming.

This is a perl command that should do what you need though:

oldscript.sh | perl -ne '$log=$_.`cat my_log.txt`; open(F, ">", "my_log.txt"); print F $log; print'

Juts change the path to my_log.txt for your needs.