× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to send output of a script to both a log file and the screen

Jessica Owensby
Feb 04, 2017
<p>Sometimes you will want to capture the output of a script into a log (maybe for later reference or use) while still viewing reali time what the script is logging.  </p> <p>Here's how you can do this with a simple linux command:</p> <p><code>./my_awesome_script.sh 2&gt;&amp;1 | tee my_awesome_log.log</code></p> <p>The first part of this command (2&gt;&amp;1) combines the error stream and the input steam into one which is then piped to the tee command.  The tee command reads this input and writes it to both standard output and the my_awesome_log.log file, effectivelly duplicating the input.</p>
comments powered by Disqus