[kwlug-disc] Capturing output in scripts

Khalid Baheyeldin kb at 2bits.com
Thu Aug 21 15:02:33 EDT 2014


Good idea. Thanks!


On Thu, Aug 21, 2014 at 2:42 PM, Chris Craig <kwlug.org at ciotog.net> wrote:

> You could put your commands in a function, then call the function in
> the subshell call.
>
> On 21 August 2014 12:35, Khalid Baheyeldin <kb at 2bits.com> wrote:
> > For years I have been using the following technique to capture output
> > (stdout and stderr), for emailing the results.
> >
> > (
> > command
> > command
> > if [ ....
> >   command
> > else
> >   command
> > fi
> > ...
> > ) 2>&1 > /tmp/logfile
> >
> > Basically, the () is a subshell, and its output is captured.
> >
> > Then the logfile can be kept or sent via email from the same script,
> often
> > conditionally if there are errors e.g.:
> >
> > mail -s "script output" me at example.com < /tmp/logfile
> >
> > The only thing that is annoying is that vim syntax highlighting gets
> thrown
> > off for the stuff in between the ().
> >
> > Anyone knows of a way around this? Either alternates to capturing output
> >
> > I thought about the script command:
> >
> > script -c myscript /tmp/logfile
> >
> > 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.
> >
> > Another approach is to fix vim syntax highlight, but I don't know how.
> >
> > Any ideas?
> > --
> > Khalid M. Baheyeldin
> > 2bits.com, Inc.
> > Fast Reliable Drupal
> > Drupal optimization, development, customization and consulting.
> > Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
> > Simplicity is the ultimate sophistication. --   Leonardo da Vinci
> > For every complex problem, there is an answer that is clear, simple, and
> > wrong." -- H.L. Mencken
> >
> > _______________________________________________
> > kwlug-disc mailing list
> > kwlug-disc at kwlug.org
> > http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
> >
>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>



-- 
Khalid M. Baheyeldin
2bits.com, Inc.
Fast Reliable Drupal
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
For every complex problem, there is an answer that is clear, simple, and
wrong." -- H.L. Mencken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20140821/d064a33f/attachment.htm>


More information about the kwlug-disc mailing list