<?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: How do you capture all terminal output resulting from running a script? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730140#M721808</link>
    <description>No problem.  If it's as good as it sounds from the other posting, it will have saved me a LOT of work.  Have another hat!</description>
    <pubDate>Thu, 23 May 2002 18:18:03 GMT</pubDate>
    <dc:creator>Kurt Renner</dc:creator>
    <dc:date>2002-05-23T18:18:03Z</dc:date>
    <item>
      <title>How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730127#M721795</link>
      <description>I am developing a script which will take our admins through the entire process of securing a HP-UX machine according to our corporate stds.  I want a log file of all the activity performed within this script that can be used for later review in case there were problem areas in configuring the system.  &lt;BR /&gt;&lt;BR /&gt;One way I know I could do this is to use "tee" to write both to the terminal and to a log file.  However, the scripting style I want to use is to call functions within an "if" statement.  The functions will return 0 if successful, and non-zero if it is unsuccessful... similar to the following code.&lt;BR /&gt;&lt;BR /&gt;if SomeFunction; then&lt;BR /&gt;  State=/bin/true&lt;BR /&gt;else&lt;BR /&gt;  State=/bin/false&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;If I were to include a "| tee -a ${OutputFile}", it will skew the return code value of the function, and will always be true if the "tee" command is successful.&lt;BR /&gt;&lt;BR /&gt;I could use tee in a pipeline when the script is initiated.  I could also use the "script" command to capture it as well, but then every user would have to remember to invoke the script in one of these 2 ways... which wouldn't happen.&lt;BR /&gt;&lt;BR /&gt;I tried putting the "script" command within the script, but as the man page says, I just get a spawned shell, and the script then proceeds after I exit the spawned shell... not capturing the output as I intend.&lt;BR /&gt;&lt;BR /&gt;A good example of what I am trying to accomplish is the way the swintall command operates in non-interactive mode.  All the terminal I/O is displayed to the user, and also captured in a file in the /var/adm/sw/ directory.&lt;BR /&gt;&lt;BR /&gt;I'm looking to direct STDERR and STDOUT for the entire script, not individual commands, and to somehow do it within the script itself.&lt;BR /&gt;&lt;BR /&gt;Any ideas would be appreciated.</description>
      <pubDate>Thu, 23 May 2002 12:44:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730127#M721795</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-23T12:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730128#M721796</link>
      <description>This may be what your looking for.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6ac253921f1ad5118fef0090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6ac253921f1ad5118fef0090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;GL,&lt;BR /&gt;C</description>
      <pubDate>Thu, 23 May 2002 12:47:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730128#M721796</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2002-05-23T12:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730129#M721797</link>
      <description>Put a wrapper around the script - another script that invokes your original with stderr and stdout redirected.&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 23 May 2002 12:48:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730129#M721797</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-05-23T12:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730130#M721798</link>
      <description>Before you start the "secure" process, type in "script /tmp/filename", then proceed to do your magic. If you use Exceed, you can do the same by "ctrl-leftmousebutton" then select "log to file".&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 23 May 2002 12:52:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730130#M721798</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-23T12:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730131#M721799</link>
      <description>Here is an approach you might not have expected in this forum:&lt;BR /&gt;&lt;BR /&gt;Try using a video/screen capture device using an xterm.  You could voice over with the 'why', while the trainee see the commands being entered.&lt;BR /&gt;&lt;BR /&gt;I know it seems a bit hollywood, but I've used many such training materials, and the trainees really benefit from the commentary and the examples.&lt;BR /&gt;&lt;BR /&gt;Good Luck.</description>
      <pubDate>Thu, 23 May 2002 12:53:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730131#M721799</guid>
      <dc:creator>Robert Gamble</dc:creator>
      <dc:date>2002-05-23T12:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730132#M721800</link>
      <description>Disregard previous response - after I thought about it for a minute, I realized that isn't going to do anything for you.  Oh well.&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 23 May 2002 12:55:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730132#M721800</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-05-23T12:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730133#M721801</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;I think you are trying to capture the std output and the std err that gets displayed on the terminal when the script is run. Try this,&lt;BR /&gt;&lt;BR /&gt;sh script &amp;gt;script.run.log 2&amp;gt;&amp;amp;1&lt;BR /&gt;or&lt;BR /&gt;./script &amp;gt;script.run.log 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;regds&lt;BR /&gt;</description>
      <pubDate>Thu, 23 May 2002 12:56:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730133#M721801</guid>
      <dc:creator>Sanjay_6</dc:creator>
      <dc:date>2002-05-23T12:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730134#M721802</link>
      <description>Probably the easiest way is to use script tracing (set -x or run the script as: sh -x script_name) and redirect STDERR to a file. Unfortunately, the default action for function calls is to turn off set -x so it would have to appear in every function too. &lt;BR /&gt;&lt;BR /&gt;If you don't want all the trace statements, then you'll be best off writing a separate function for displaying all messages. So instead of writing:&lt;BR /&gt;&lt;BR /&gt;echo "Enter new data: \c"&lt;BR /&gt;&lt;BR /&gt;you would use (assumes $LOGFILE has already been defined):&lt;BR /&gt;&lt;BR /&gt;LogWrite "Enter new data: \c"&lt;BR /&gt;&lt;BR /&gt;and write a function like:&lt;BR /&gt;&lt;BR /&gt;function LogWrite&lt;BR /&gt;{&lt;BR /&gt;print "$@" | tee -a $LOGFILE&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;And to capture non-zero exit codes seen by the shell put this trap statement at the beginning:&lt;BR /&gt;&lt;BR /&gt;trap 'ErrWrite $0: A non-zero returncode occurred at line $LINENO' ERR&lt;BR /&gt;&lt;BR /&gt;This trap statement will add the name of the script and the line number where any error return was detected. You may want to tee the error output into a different file such as $ERRLOG. The function ErrWrite would be:&lt;BR /&gt;&lt;BR /&gt;function ErrWrite&lt;BR /&gt;{&lt;BR /&gt;print "$@" | tee -a $ERRLOG&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;For calls to processes that may return STDERR, you'll have to add: 2&amp;gt;&amp;gt;$LOGFILE (or 2&amp;gt;&amp;gt;$ERRLOG) to the end of each process call.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 May 2002 13:01:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730134#M721802</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2002-05-23T13:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730135#M721803</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;As shown &lt;BR /&gt;&lt;BR /&gt;script /tmp/file&lt;BR /&gt;&lt;BR /&gt;Prompt will return&lt;BR /&gt;&lt;BR /&gt;script&lt;BR /&gt;&lt;BR /&gt;At end of script &lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;Prompt will return&lt;BR /&gt;&lt;BR /&gt;All output to the screen is in /tmp/file&lt;BR /&gt;&lt;BR /&gt;To debug the script if needed put set -x as&lt;BR /&gt;the first non comment line and all commands are also echoed as they are executed&lt;BR /&gt;&lt;BR /&gt;                    steve steel</description>
      <pubDate>Thu, 23 May 2002 13:03:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730135#M721803</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2002-05-23T13:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730136#M721804</link>
      <description>Thanks a bunch for all the suggestions.  I really like the quick responses I get when posting a question in this forum.  &lt;BR /&gt;&lt;BR /&gt;While I didn't use any of the ideas exclusively, I got a different idea from them, and thought I would share my solution:&lt;BR /&gt;&lt;BR /&gt;Here's the code I put in the first part of the Main section of my script after all my function declarations:&lt;BR /&gt;&lt;BR /&gt;: ${ScriptLog:="/tmp/${0##*/}.log"}; export ScriptLog&lt;BR /&gt;: ${FirstTimeThru:=/bin/true}; export FirstTimeThru&lt;BR /&gt;&lt;BR /&gt;if ${FirstTimeThru}; then&lt;BR /&gt;  test -f "${ScriptLog} &amp;amp;&amp;amp; /usr/bin/mv ${ScriptLog} ${ScriptLog}.old || &amp;gt; ${ScriptLog}&lt;BR /&gt;  export FirstTimeThru="/bin/false"&lt;BR /&gt;  ${0} $@ 2&amp;gt;&amp;amp;1 | tee -a ${ScriptLog}&lt;BR /&gt;else&lt;BR /&gt;  exit $?&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I've tested this logic, and it gives me exactly what I was looking for.  Thanks for all the suggestions!!!</description>
      <pubDate>Thu, 23 May 2002 17:31:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730136#M721804</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-23T17:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730137#M721805</link>
      <description>Kurt,&lt;BR /&gt;&lt;BR /&gt;Have you checked HP-UX Bastille?  It's a tool to help you secure your systems.  See &lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc2d291ccb36bd611abdb0090277a778c,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc2d291ccb36bd611abdb0090277a778c,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck,&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 23 May 2002 17:37:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730137#M721805</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-05-23T17:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730138#M721806</link>
      <description>It seems I had heard about it many months ago, and had not gotten a chance to do anything with it, and in the meantime had completely forgotten about it.  I sent off for it.  Hopefully I will get it today yet, and take it for a spin.  &lt;BR /&gt;&lt;BR /&gt;Thanks for the tip.  It is much appreciated!</description>
      <pubDate>Thu, 23 May 2002 18:08:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730138#M721806</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-23T18:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730139#M721807</link>
      <description>You're very welcome for the tip.  And thanks for the new hat.  You pushed me over the edge - thanks.&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 23 May 2002 18:11:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730139#M721807</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-05-23T18:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do you capture all terminal output resulting from running a script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730140#M721808</link>
      <description>No problem.  If it's as good as it sounds from the other posting, it will have saved me a LOT of work.  Have another hat!</description>
      <pubDate>Thu, 23 May 2002 18:18:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-you-capture-all-terminal-output-resulting-from-running-a/m-p/2730140#M721808</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2002-05-23T18:18:03Z</dc:date>
    </item>
  </channel>
</rss>

