<?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: Script logging in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600301#M855576</link>
    <description>why not take a look at the script command?&lt;BR /&gt;man script</description>
    <pubDate>Wed, 24 Oct 2001 10:00:38 GMT</pubDate>
    <dc:creator>melvyn burnard</dc:creator>
    <dc:date>2001-10-24T10:00:38Z</dc:date>
    <item>
      <title>Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600296#M855571</link>
      <description>When writing a shell script is there a way of directing all output and error to a log without having to add a &amp;gt;&amp;gt; $log to each command?</description>
      <pubDate>Wed, 24 Oct 2001 09:25:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600296#M855571</guid>
      <dc:creator>Malcolm McKenzie</dc:creator>
      <dc:date>2001-10-24T09:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600297#M855572</link>
      <description>Hi Malcolm,&lt;BR /&gt;&lt;BR /&gt;Can you not redirect the script's output when you run it, e.g.&lt;BR /&gt;&lt;BR /&gt;./my_script.sh &amp;gt;log.out 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.</description>
      <pubDate>Wed, 24 Oct 2001 09:37:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600297#M855572</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-10-24T09:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600298#M855573</link>
      <description>An easy way is to call the script from another script which has redirect to one log, or by command line ( #your_script &amp;gt; log 2&amp;gt;&amp;amp;1), or make the 'main' part of the script a function.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;----------------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/tmp/mylog&lt;BR /&gt;&lt;BR /&gt;your_original_script()&lt;BR /&gt;{&lt;BR /&gt;...your script...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;your_original_script &amp;gt;&amp;gt; $LOG 2&amp;gt;&amp;amp;1&lt;BR /&gt;----------------------------&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;James</description>
      <pubDate>Wed, 24 Oct 2001 09:37:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600298#M855573</guid>
      <dc:creator>James Beamish-White</dc:creator>
      <dc:date>2001-10-24T09:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600299#M855574</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Yep, run script like:&lt;BR /&gt;&lt;BR /&gt;&amp;lt;script&amp;gt; 1&amp;gt;normal_log 2&amp;gt;error_log&lt;BR /&gt;&lt;BR /&gt;E.</description>
      <pubDate>Wed, 24 Oct 2001 09:39:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600299#M855574</guid>
      <dc:creator>Eugen Cocalea</dc:creator>
      <dc:date>2001-10-24T09:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600300#M855575</link>
      <description>You can affect the environment for the whole script by using the exec command:&lt;BR /&gt;&lt;BR /&gt;exec 2&amp;gt;&amp;amp;1 &amp;gt;${Logfile}&lt;BR /&gt;&lt;BR /&gt;But, as most shell scripts are run both as batch and by the admin I'd advise using a system that sends output to both the Logfile and stdout - the normal way of doing this is to do summat like:&lt;BR /&gt;&lt;BR /&gt;echo "foo" 2&amp;gt;&amp;amp;1 | tee -a ${Logfile}&lt;BR /&gt;&lt;BR /&gt;This has 2 problems:&lt;BR /&gt; * increases size of script&lt;BR /&gt; * loses return code of the command before the tee...&lt;BR /&gt;&lt;BR /&gt;What I do is have a function which runs a command, handles the logging and returns the valid return code [it also adds date time and program name to the logfile]:&lt;BR /&gt;function LogExec&lt;BR /&gt;{&lt;BR /&gt;   typeset Status&lt;BR /&gt;   typeset TempFile=$(mktemp)&lt;BR /&gt;&lt;BR /&gt;   ${@} 2&amp;gt;&amp;amp;1 &amp;gt;${TempFile}&lt;BR /&gt;   Status=${?}&lt;BR /&gt;&lt;BR /&gt;   while read line&lt;BR /&gt;   do&lt;BR /&gt;      print "[${1##*/}] $(date  "+%Y%m%d %H:%M:%S") ${line}" | tee -a ${LogFile}&lt;BR /&gt;   done &amp;lt;${TempFile}&lt;BR /&gt;&lt;BR /&gt;   rm -f ${TempFile}&lt;BR /&gt;   return ${Status}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;So when you have this you just need to do the following:&lt;BR /&gt;   LogExec rm foo*&lt;BR /&gt;&lt;BR /&gt;instead of &lt;BR /&gt;   rm foo* | tee -a ${LogFile}&lt;BR /&gt;&lt;BR /&gt;dave&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2001 09:59:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600300#M855575</guid>
      <dc:creator>David Lodge</dc:creator>
      <dc:date>2001-10-24T09:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600301#M855576</link>
      <description>why not take a look at the script command?&lt;BR /&gt;man script</description>
      <pubDate>Wed, 24 Oct 2001 10:00:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600301#M855576</guid>
      <dc:creator>melvyn burnard</dc:creator>
      <dc:date>2001-10-24T10:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600302#M855577</link>
      <description>&lt;BR /&gt;I tried the script command but found this the best solution.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh &lt;BR /&gt;exec &amp;gt; $log 2&amp;gt;&amp;amp;1 &lt;BR /&gt;&lt;BR /&gt;Thanks for the tips.&lt;BR /&gt;&lt;BR /&gt;Malcolm</description>
      <pubDate>Wed, 24 Oct 2001 10:43:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-logging/m-p/2600302#M855577</guid>
      <dc:creator>Malcolm McKenzie</dc:creator>
      <dc:date>2001-10-24T10:43:28Z</dc:date>
    </item>
  </channel>
</rss>

