<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: exec redirection plus tee?  possible? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922125#M109765</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;==========================&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;exec 1&amp;gt;/tmp/ls.log 2&amp;gt;&amp;amp;1&lt;BR /&gt;ls |tee /dev/tty&lt;BR /&gt;==========================&lt;BR /&gt;&lt;BR /&gt;this should log to the screen and to the file.&lt;BR /&gt;&lt;BR /&gt;To see if you're in interactive mode, you can use the syntax:&lt;BR /&gt;&lt;BR /&gt;if [ -t 0 ] ; then&lt;BR /&gt; ...&lt;BR /&gt; ...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;rgds, Robin</description>
    <pubDate>Fri, 07 Mar 2003 15:25:51 GMT</pubDate>
    <dc:creator>Robin Wakefield</dc:creator>
    <dc:date>2003-03-07T15:25:51Z</dc:date>
    <item>
      <title>exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922122#M109762</link>
      <description>Using the handy functionality of exec to redirect filehandles for an entire script has really cleaned up our scripts:&lt;BR /&gt;&lt;BR /&gt;exec 1&amp;gt;log 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;...but now I'm wondering if there's any way to use that in combination with tee.&lt;BR /&gt;&lt;BR /&gt;The end result that I want is:&lt;BR /&gt;- Only specify redirection once, at the beginning of the script.&lt;BR /&gt;&lt;BR /&gt;- Always have stdout go to a log file.&lt;BR /&gt;&lt;BR /&gt;- If the script was run on an interactive terminal, then also have stdout go to the terminal (and still to the logfile).&lt;BR /&gt;&lt;BR /&gt;A simple function to both send a message to a log and to the terminal isn't enough - I need to send stdout both places.&lt;BR /&gt;&lt;BR /&gt;I guess I could buffer all output into variables and then echo it, but that gets ugly.&lt;BR /&gt;&lt;BR /&gt;I think what I really need is some way to attach stdout to two file descriptors and then redirect those file descriptors separately.&lt;BR /&gt;&lt;BR /&gt;Possible?  Suggestions?</description>
      <pubDate>Fri, 07 Mar 2003 14:26:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922122#M109762</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2003-03-07T14:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922123#M109763</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Have you ever looked at the script command&lt;BR /&gt;&lt;BR /&gt;It will do what you ask.&lt;BR /&gt;&lt;BR /&gt;You get normal i/o to the screen and a copy in a log.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;            Steve Steel</description>
      <pubDate>Fri, 07 Mar 2003 14:29:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922123#M109763</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2003-03-07T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922124#M109764</link>
      <description>Script - Hmmm...  That's an approach I hadn't thought of.  I don't really want to launch a separate sub-shell for every process though and I'm not sure what I'd do with the output on stdout when the script is run non-interactively.  That would also complicate quoting quite a bit.</description>
      <pubDate>Fri, 07 Mar 2003 15:16:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922124#M109764</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2003-03-07T15:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922125#M109765</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;==========================&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;exec 1&amp;gt;/tmp/ls.log 2&amp;gt;&amp;amp;1&lt;BR /&gt;ls |tee /dev/tty&lt;BR /&gt;==========================&lt;BR /&gt;&lt;BR /&gt;this should log to the screen and to the file.&lt;BR /&gt;&lt;BR /&gt;To see if you're in interactive mode, you can use the syntax:&lt;BR /&gt;&lt;BR /&gt;if [ -t 0 ] ; then&lt;BR /&gt; ...&lt;BR /&gt; ...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;rgds, Robin</description>
      <pubDate>Fri, 07 Mar 2003 15:25:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922125#M109765</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2003-03-07T15:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922126#M109766</link>
      <description>Neither script or tee will do what you want because having used exec, all the output is going to your log file only.&lt;BR /&gt;&lt;BR /&gt;You could experiment with 'tail -f' to display the logfile as it is written to your terminal.&lt;BR /&gt;&lt;BR /&gt;Simple way:&lt;BR /&gt;&lt;BR /&gt;&lt;YOURSCRIPT&gt;&lt;/YOURSCRIPT&gt;tail -f &lt;LOGFILE&gt;&lt;BR /&gt;You have to ctrl-C the tail command when the script finishes.&lt;BR /&gt;&lt;BR /&gt;Possible scripted way, you may only want to do this if a certain flag is supplied to the script:&lt;BR /&gt;&lt;BR /&gt;CHILD=""&lt;BR /&gt;exec 1&amp;gt;log 2&amp;gt;&amp;amp;1&lt;BR /&gt;if [[ -t 1 ]]; # controlling terminal exists&lt;BR /&gt;then tail -f &lt;LOG&gt; &amp;amp;&lt;BR /&gt; CHILD=${!}&lt;BR /&gt;fi&lt;BR /&gt;... body of script ...&lt;BR /&gt;&lt;BR /&gt;Yourscript exit code to kill the tail:&lt;BR /&gt;if [[ -n ${CHILD} ]];&lt;BR /&gt;then kill ${CHILD}&lt;BR /&gt;fi&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John&lt;BR /&gt;&lt;/LOG&gt;&lt;/LOGFILE&gt;</description>
      <pubDate>Fri, 07 Mar 2003 15:26:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922126#M109766</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2003-03-07T15:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922127#M109767</link>
      <description>Robin, thanks, but that method doesn't work - the pipe into tee overrides the redirection from exec for that command.&lt;BR /&gt;&lt;BR /&gt;And if it did work, then I'd be back at the beginning, appending something to every command.</description>
      <pubDate>Fri, 07 Mar 2003 16:40:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922127#M109767</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2003-03-07T16:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922128#M109768</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;Can't eyeball that one and tell if it'll work, but it's going down the only path I've been able to imagine so far - forking so that one process does the actual work and another displays the output on an interactive terminal.  I was really hoping there was a simpler way. :-)</description>
      <pubDate>Fri, 07 Mar 2003 16:44:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922128#M109768</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2003-03-07T16:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922129#M109769</link>
      <description>well here is one way&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;logfile=&lt;BR /&gt;tty=$(tty)&lt;BR /&gt;exec 3&amp;gt; $tty&lt;BR /&gt;if [ -t = 0 ] ;then&lt;BR /&gt;/usr/local/bin/outputredirect $tty $logfile |&amp;amp;&lt;BR /&gt;exec &amp;gt;&amp;amp;p&lt;BR /&gt;else&lt;BR /&gt;exec 1&amp;gt;$logfile 2&amp;gt;&amp;amp;1&lt;BR /&gt;fi&lt;BR /&gt;rest of your script&lt;BR /&gt;&lt;BR /&gt;file outputredirect&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;tty=$1&lt;BR /&gt;logfile=$2&lt;BR /&gt;&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;print $line &amp;gt;&amp;gt; $logfile&lt;BR /&gt;print $line &amp;gt; $tty&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;give that a try and see how it works for you.</description>
      <pubDate>Sat, 08 Mar 2003 01:44:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922129#M109769</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-03-08T01:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922130#M109770</link>
      <description>At the moment I don't have access to either a UNIX or Linux system, so I'll have to wing it. I'm thinking of co-processes... Try this in the POSIX shell:&lt;BR /&gt;&lt;BR /&gt;logfile=$0.log&lt;BR /&gt;if [ -t 0 ]&lt;BR /&gt;then&lt;BR /&gt;tee $logfile |&amp;amp;&lt;BR /&gt;exec 1&amp;gt;&amp;amp;p 2&amp;gt;&amp;amp;p&lt;BR /&gt;else&lt;BR /&gt;exec 1&amp;gt;$logfile 2&amp;gt;&amp;amp;1&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Sun, 09 Mar 2003 23:55:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922130#M109770</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-03-09T23:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922131#M109771</link>
      <description>Jordan, yours was close but didn't quite work.  Curt, yours worked.&lt;BR /&gt;&lt;BR /&gt;BTW, the bits about co-processes in the manual pages never made sense until now - thanks for being great teachers! :-)&lt;BR /&gt;&lt;BR /&gt;Curt, when I first tested your method, I didn't think it worked - not sure how I goofed, but it does work perfectly, so if you want the rest of the points, just post again and I'll assign them.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help, everyone.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Mar 2003 15:22:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922131#M109771</guid>
      <dc:creator>Trever Furnish</dc:creator>
      <dc:date>2003-03-10T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922132#M109772</link>
      <description>a couple of additions,&lt;BR /&gt;&lt;BR /&gt;you probably caught that i left out redirection of stderr to the coprocess.&lt;BR /&gt;&lt;BR /&gt;/usr/local/bin/outputredirect $tty $logfile |&amp;amp; &lt;BR /&gt;exec &amp;gt;&amp;amp;p &lt;BR /&gt;&lt;BR /&gt;should have been&lt;BR /&gt;/usr/local/bin/outputredirect $tty $logfile |&amp;amp; &lt;BR /&gt;exec &amp;gt;&amp;amp;p 2&amp;gt;&amp;amp;p&lt;BR /&gt;&lt;BR /&gt;the file outputredirect works using the tee command also:&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;tee -a $2 &amp;gt;$1&lt;BR /&gt;&lt;BR /&gt;but I can not tell you why it works in a seperate file but not as part of the shell script</description>
      <pubDate>Mon, 10 Mar 2003 15:43:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922132#M109772</guid>
      <dc:creator>Curtis Larson_2</dc:creator>
      <dc:date>2003-03-10T15:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922133#M109773</link>
      <description>but you don't need the outputredirect file if you use&lt;BR /&gt;/usr/bin/ksh -c tee -a $logfile &amp;gt;$tty |&amp;amp;&lt;BR /&gt;&lt;BR /&gt;that way everything can just be in the one shell script.</description>
      <pubDate>Mon, 10 Mar 2003 15:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922133#M109773</guid>
      <dc:creator>Curtis Larson_2</dc:creator>
      <dc:date>2003-03-10T15:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922134#M109774</link>
      <description>&lt;BR /&gt;Oh, I'm being stupid. stdout from the co-process returns to the parent script. This means that, in this case, tee is writing to the log file, but also back to the script.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Mar 2003 19:45:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922134#M109774</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-03-10T19:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922135#M109775</link>
      <description>&lt;BR /&gt;Got it! Simple fix. You must also tell tee to send stdout to stderr (aka tty) when becoming a co-proc so it doesn't map back to the returning pipe.&lt;BR /&gt;&lt;BR /&gt;logfile=$0.log&lt;BR /&gt;if [ -t 0 ]&lt;BR /&gt;then&lt;BR /&gt;tee $logfile &amp;gt;&amp;amp;2 |&amp;amp;&lt;BR /&gt;exec &amp;gt;&amp;amp;p 2&amp;gt;&amp;amp;1&lt;BR /&gt;else&lt;BR /&gt;exec &amp;gt;$logfile 2&amp;gt;&amp;amp;1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Mar 2003 20:04:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922135#M109775</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-03-10T20:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: exec redirection plus tee?  possible?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922136#M109776</link>
      <description>&lt;BR /&gt;Curtis' method accomplishes the same task.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Mar 2003 20:06:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/exec-redirection-plus-tee-possible/m-p/2922136#M109776</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-03-10T20:06:14Z</dc:date>
    </item>
  </channel>
</rss>

