Capturing Console Output


I was looking through a Bash Script and I was particularly focused on how logging is being accomplished.

If not done fully well, each step will have two steps.  One will write to the screen ( stdout) and the other to a log file.


I am familiar with tee, but my awareness came about through MS Windows.

It basically allows one to capture stdout output to a file, as well.

Linux /Bash


In our exercise, we will have two applications.

One a client and the other a controller.

The client will do the work and the controller will co-ordinate and ensure that the client’s work is captured.


  • Client
    • Do very little
      • Simple commands such as
        • hostname
        • date
        • uptime
  • Controller
    • Also do so little
      • Generate Log file names
        • Base file name
        • Timestamp file name
      • Invoke client and capture into base file name
      • Copy base file unto TS file


App – Client


echo -n  "Host :-  "

uname -n

echo "Date :- $(date)"

echo "uptime"


App – Manager


function getLogFileName()

  local _baseFolder=${1}
  local _addTS=${2}
  local _filename=""
  local _moduleName=""
  local _TSFormat="%Y%m%d_%H%M%S"
  local _TSAsString=""

  _moduleName=`basename "$0"`

  _TSAsString=$(date +$_TSFormat)


  if [ $_addTS -eq 1 ]




  echo $_filename

#Get Log File Name ( base )
_filenameLogBase=$(getLogFileName '/tmp' '0' )

#Get Log File Name ( TS )
_filenameLogTS=$(getLogFileName '/tmp' '1' )

#As part of debug display Log file name
echo "Log file name is $_filenameLogTS"

# indicate client app

#execute app and log output to _filename
(exec "$client") | tee $_filenameLogBase

#copy base log file to log file TS
cp $_filenameLogBase $_filenameLogTS


MS Windows

Here are good MS Windows version of tee

  1. Google Code Archive
    • wintee
      • Links

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s