In a production web environment that has several web servers, databases and mail daemons running countless domains, having a cool set of utilities is key for monitoring, logging and debugging.
A number of scripts I have written can have a 'testing' parameter handed to them so when they are run with that parameter set they will echo out all kinds useful information. Most of the time sending this to a log file for parsing later is good enough. But, sometimes I have a need to watch it as it happens while still writing the output of my script to a file.
Here is where the command 'tee' comes in very handy.
From the man page 'tee' is defined as follows:
'tee - read from standard input and write to standard output and files'
Simple enough, eh? You bet it is.
For instance, let's say I have written a script called uber-leet-script.sh, but I want to watch the output as it runs and still log the output to a file called 'uber-leet-script.out'. Just for simplicity, we will assume both the script (which I have chmod'd 755) and the file I want to log the output to are in the same directory.
I would run my script like so from the command line:
$ ./uber-leet-script.sh | tee ./uber-leet-script.out
Once I hit enter, I see all the output. Sometimes the bug in my script will be blatently obvious in what I see from the output and I can just CTRL-C it on the spot. Other times it may scroll past so fast and I could miss the telling bit of output. No problem there because I have the file, uber-leet-script.out to parse through until my heart's content.