title: Bash: Execute a script remotely, show few logs on the terminal and redirect rest of the logs to log file
body: <p>I have a case where I want to run the bash script remotely. That bash script prints some logs. I want to show only few logs on the screen and move rest of the logs in log file. Log file is present on the host from where I am executing the bash script remotely.
  For example,
  I have 2 machines Host A and Host B. Following script is present on Host A</p>
  
  <pre><code>echo  "Executing the script on $(hostname) at $(date)" # &lt;&lt;&lt;&lt; I want this log in log file
  echo -n "[Info] Importing docker images from tar files ..." # &lt;&lt;&lt;&lt; I want this log on terminal
  for file_path in $tar_file_paths
  do
     cat ${file_path} | docker import - ${file_path}:${tag}
     if [[ $? -ne 0 ]]; then
        echo "[Error] Failed to import ${file_path}
        exit 1
     fi
     echo -n "." # &lt;&lt;&lt;&lt; I want this log on terminal
  done
  echo " [Done]" # &lt;&lt;&lt;&lt; I want this log on terminal
  
  echo  "Done with executing the script on $(hostname) at $(date)" # &lt;&lt;&lt;&lt; I want this log in log file
  </code></pre>
  
  <p>I am transferring the script from Host A to Host B and executing it like follows,</p>
  
  <pre><code>ssh -i /home/centos/.ssh/id_rsa centos@192.168.235.10:/tmp/test-script.sh
  </code></pre>
  
  <p>Above command is again a part of some script. When the above command gets executed then I want something like following on the terminal</p>
  
  <pre><code>[Info] Importing docker images from tar files .................... [Done]
  </code></pre>
  
  <p>and for rest of the logs as shown in the script, I want them in some log file located on Host A.</p>
  
  <p>One approach I tried is like maintaining a temporary log file on the Host B and once the script is done then append the content of the temporary log file from Host B to main log file on Host A. In this case I was redirecting the logs which I don't want to show on the terminal, to temporary log file. 
  But, This is kind of not suitable for my use case. I'll be monitoring the main log file using tail and main log file look like hang when the remote execution happens.</p>