<div dir="ltr"><div>For years I have been using the following technique to capture output (stdout and stderr), for emailing the results.<br><br>(<br></div><div>command <br>command<br>if [ ....<br></div><div>  command<br></div>
<div>else <br></div><div>  command<br></div><div>fi<br>...<br></div><div>) 2>&1 > /tmp/logfile<br><br></div><div>Basically, the () is a subshell, and its output is captured.<br><br>Then the logfile can be kept or sent via email from the same script, often conditionally if there are errors e.g.:<br>
<br></div><div>mail -s "script output" <a href="mailto:me@example.com">me@example.com</a> < /tmp/logfile<br><br></div><div>The only thing that is annoying is that vim syntax highlighting gets thrown off for the stuff in between the ().<br>
<br></div><div>Anyone knows of a way around this? Either alternates to capturing output<br><br></div><div>I thought about the script command:<br><br>script -c myscript /tmp/logfile<br><br>But then I have to break every script into two files, one a wrapper that runs the real script and emails its output and the script proper itself. Also, it annoyingly captures everything like terminal escape codes and such.<br>
</div><div><br></div><div>Another approach is to fix vim syntax highlight, but I don't know how.<br><br></div><div>Any ideas?<br clear="all"></div><div>-- <br>Khalid M. Baheyeldin<br><a href="http://2bits.com" target="_blank">2bits.com</a>, Inc.<br>
Fast Reliable Drupal<br>Drupal optimization, development, customization and consulting.<br>Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra<br>Simplicity is the ultimate sophistication. --   Leonardo da Vinci<br>
For every complex problem, there is an answer that is clear, simple, and wrong." -- H.L. Mencken<br>
</div></div>