<?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: LOGGING OUTPUT in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170285#M681963</link>
    <description>&lt;!--!*#--&gt;HI (again) Rex:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; and if command name is TLC_xfer.sh the LOG name should be similar&lt;BR /&gt;&lt;BR /&gt;Yes, the '$(basename $0)' gets the basename of the process.&lt;BR /&gt;&lt;BR /&gt;Actually, putting everything together we can use accomodate your 'tee'.  Consider:&lt;BR /&gt;&lt;BR /&gt;# ./mysh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0)&lt;BR /&gt;typeset TMP=/var/tmp/$(basename $0).$$&lt;BR /&gt;trap 'rm -f ${TMP}' EXIT&lt;BR /&gt;exec 4&amp;gt;&amp;amp;1 #...duplicate STDOUT to FD-4&lt;BR /&gt;exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;ls -l &amp;gt; ${TMP}&lt;BR /&gt;cat ${TMP} &amp;gt;&amp;amp;4&lt;BR /&gt;cat ${TMP} &amp;gt;&amp;gt; ${LOG}&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Fri, 17 Apr 2009 16:53:32 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-04-17T16:53:32Z</dc:date>
    <item>
      <title>LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170275#M681953</link>
      <description>I have several scripts that run in cron, I need to output information from the running of these scripts into logfiles. &lt;BR /&gt;&lt;BR /&gt;I am curious what others are doing as best practice to log information? &lt;BR /&gt;&lt;BR /&gt;My initial thought was to use the command in cron that sends stdout/stderr to the log by appending a redirection in the cron. &lt;BR /&gt;&lt;BR /&gt;IE: &lt;BR /&gt;* * * * * /usr/local/bin/scriptname &amp;gt; /tmp/logname.log 2&amp;gt;&amp;amp;1 &lt;BR /&gt;&lt;BR /&gt;Or would it be better to log output from within the script itself ? &lt;BR /&gt;&lt;BR /&gt;IE:&lt;BR /&gt;#!/bin/sh &lt;BR /&gt;LOG_FILE=/tmp/logname.log &lt;BR /&gt;&lt;BR /&gt;command |tee $LOG_FILE 2&amp;gt;&amp;amp;1 &lt;BR /&gt;&lt;BR /&gt;One of the scripts is as follows by default, &lt;BR /&gt;&lt;BR /&gt;crontab: &lt;BR /&gt;15 20 * * * /usr/local/bin/TLC_xfer.sh &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;rm -f /tmp/staff_RAL.csv &lt;BR /&gt;rm -f /tmp/staff_WST.csv&lt;BR /&gt;&lt;BR /&gt;export INFORMIXSERVER=pei&lt;BR /&gt;.  /spi/spitools/bin/spi_prof.sh&lt;BR /&gt;&lt;BR /&gt;/usr/informix/bin/isql wstplus /usr/informix/bin/isql wstplus /usr/informix/bin/isql ralplus &lt;BR /&gt;cat /usr/local/bin/ral_tlc_header /tmp/staff_RAL.csv  &amp;gt; /tmp/staff_patron_download_RAL.csv&lt;BR /&gt;cat /usr/local/bin/wst_tlc_header /tmp/staff_WST.csv /tmp/staff-dc_WST.csv  &amp;gt; /tmp/staff_patron_download_WST.csv&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;IF I modify the crontab What would be the command? &lt;BR /&gt;&lt;BR /&gt;If I modify the script to log to /tmp/tlcmove.log &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;What would be best practice to output stdout/stderr to $LOG_FIL? &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;"TLC_xfer.sh" 13 lines, 523 characters &lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG_FIL=/tmp/tlc_move.log &lt;BR /&gt;&lt;BR /&gt;(NEED TO EDIT FOR ECHO TO LOG_FIL&amp;gt;output..)&lt;BR /&gt;rm -f /tmp/staff_RAL.csv  &lt;BR /&gt;rm -f /tmp/staff_WST.csv&lt;BR /&gt;&lt;BR /&gt;export INFORMIXSERVER=pei&lt;BR /&gt;.  /spi/spitools/bin/spi_prof.sh&lt;BR /&gt;&lt;BR /&gt;/usr/informix/bin/isql wstplus /usr/informix/bin/isql wstplus /usr/informix/bin/isql ralplus &lt;BR /&gt;cat /usr/local/bin/ral_tlc_header /tmp/staff_RAL.csv  &amp;gt; /tmp/staff_patron_download_RAL.csv&lt;BR /&gt;cat /usr/local/bin/wst_tlc_header /tmp/staff_WST.csv /tmp/staff-dc_WST.csv  &amp;gt; /tmp/staff_patron_download_WST.csv&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 13:41:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170275#M681953</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T13:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170276#M681954</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;My usual preference is to put the controls in the script like:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0).$$&lt;BR /&gt;[ -t 0 ] || exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;&lt;BR /&gt;...now, if I run this interactively, the output goes to my terminal unless I explicitly redirect it.  If I use this in a 'crontask' or 'at' job, the output is automatically redirected to the LOG file.  The choice is really entirely up to you, though.  Providing redirection in 'cron' is wholly appropriate, too.&lt;BR /&gt;&lt;BR /&gt;As for temporary file cleanup, I like to do:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset TMPFILE="/var/tmp/$(basename $0).$$&lt;BR /&gt;trap 'rm -f ${TMPFILE}' EXIT&lt;BR /&gt;&lt;BR /&gt;This names the TMPFILE with the 'basename' of the running script suffixed with the current pid.  Upon exit (from anywhere in the script) the "epilog" remove of the file occurs.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 13:57:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170276#M681954</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-17T13:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170277#M681955</link>
      <description>James, &lt;BR /&gt;&lt;BR /&gt;using the "code" you suggested&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0).$$&lt;BR /&gt;[ -t 0 ] || exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;will this log all output from the rest of the script without using redirection in the command line? &lt;BR /&gt;&lt;BR /&gt;would use a "tee" I do? &lt;BR /&gt;&lt;BR /&gt;IE: &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0).$$&lt;BR /&gt;[ -t 0 ] || exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;&lt;BR /&gt;rm -f /tmp/staff_RAL.csv |tee ${LOG)&lt;BR /&gt;rm -f /tmp/staff_WST.csv  |tee ${LOG)&lt;BR /&gt;&lt;BR /&gt;... (rest of script truncated)&lt;BR /&gt;&lt;BR /&gt;#END &lt;BR /&gt;&lt;BR /&gt;Or not use a "tee"&lt;BR /&gt;OR &lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0).$$&lt;BR /&gt;[ -t 0 ] || exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;rm -f /tmp/staff_RAL.csv&lt;BR /&gt;rm -f /tmp/staff_WST.csv&lt;BR /&gt;&lt;BR /&gt;# TRUNCATED..... &lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 14:14:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170277#M681955</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T14:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170278#M681956</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; using the "code" you suggested...will this log all output from the rest of the script without using redirection in the command line? &lt;BR /&gt;&lt;BR /&gt;This will log all STDOUT and STDERR output for the duration of the script into the file "${LOG}".  _HOWEVER_ this only occurs if the process is _NOT_ associated with a terminal.  That's what the '-t 0' tests.  It says if STDIN isn't a terminal, redirect STDOUT and STDIN.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; would use a "tee" I do? &lt;BR /&gt;&lt;BR /&gt;Since you are using the '-f' switch with your 'rm' command, there isn't going to be any STDERR output for non-existent files.  Hence there is no need to use 'tee' or to redirect STDERR.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 14:26:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170278#M681956</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-17T14:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170279#M681957</link>
      <description>the rm -f was a bad example &lt;BR /&gt;&lt;BR /&gt;how about if i do something like: &lt;BR /&gt;&lt;BR /&gt;ls -la /tmp/staff*csv &lt;BR /&gt;&lt;BR /&gt;I would need to redirect through tee ${LOG)?</description>
      <pubDate>Fri, 17 Apr 2009 14:32:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170279#M681957</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T14:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170280#M681958</link>
      <description>Disregard last post I am a bit clogged with a cold and didn't see that it logs all from the script &lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 14:33:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170280#M681958</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T14:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170281#M681959</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Using 'tee' and having 'exec'd STDOUT to a file are mutually exclusive.  Once you have performed the 'exec' redirection, the output descriptors are set.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 17 Apr 2009 14:39:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170281#M681959</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-17T14:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170282#M681960</link>
      <description>Thanks James, this is going to clean up a lot of stuff for me.. &lt;BR /&gt;&lt;BR /&gt;Kudos.. Wish I could assign more the 10 points per.. &lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 14:41:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170282#M681960</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T14:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170283#M681961</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Actually, there are some other useful things we can do by duplicating file descriptors.  Consider this:&lt;BR /&gt;&lt;BR /&gt;# cat ./showme&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0).$$&lt;BR /&gt;exec 4&amp;gt;&amp;amp;1 #...duplicate STDOUT to FD-4&lt;BR /&gt;exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;print -u4 "...but this stays on my terminal!..."&lt;BR /&gt;ls -l &amp;gt;&amp;amp;4 #...and this goes to the terminal ALSO...&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 17 Apr 2009 16:31:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170283#M681961</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-17T16:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170284#M681962</link>
      <description>James, &lt;BR /&gt;I am assuming if I put the LOGGING mechanism above the commands all items if ran in cron should append to $LOG &lt;BR /&gt;&lt;BR /&gt;and if command name is TLC_xfer.sh the LOG name should be similar.. &lt;BR /&gt;&lt;BR /&gt;What I have now is as follows: &lt;BR /&gt;# more TLC_xfer.sh&lt;BR /&gt;#!/bin/sh &lt;BR /&gt;typeset LOG=/tmp/$(basename $0).$$&lt;BR /&gt;[ -t 0 ] || exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;ls -l &amp;gt;&amp;amp;4 "#send ls command to Term ..."&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;### TRUNCATE RUNNING ITEMS ### &lt;BR /&gt;/usr/informix/bin/isql ralplus &lt;BR /&gt;cat /usr/local/bin/ral_tlc_header /tmp/staff_RAL.csv  &amp;gt; /tmp/staff_patron_download_RAL.csv&lt;BR /&gt;&lt;BR /&gt;Rex&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 16:39:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170284#M681962</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T16:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170285#M681963</link>
      <description>&lt;!--!*#--&gt;HI (again) Rex:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; and if command name is TLC_xfer.sh the LOG name should be similar&lt;BR /&gt;&lt;BR /&gt;Yes, the '$(basename $0)' gets the basename of the process.&lt;BR /&gt;&lt;BR /&gt;Actually, putting everything together we can use accomodate your 'tee'.  Consider:&lt;BR /&gt;&lt;BR /&gt;# ./mysh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;typeset LOG=/var/tmp/$(basename $0)&lt;BR /&gt;typeset TMP=/var/tmp/$(basename $0).$$&lt;BR /&gt;trap 'rm -f ${TMP}' EXIT&lt;BR /&gt;exec 4&amp;gt;&amp;amp;1 #...duplicate STDOUT to FD-4&lt;BR /&gt;exec &amp;gt; ${LOG} 2&amp;gt;&amp;amp;1&lt;BR /&gt;echo "this is STDOUT..."&lt;BR /&gt;print -u2 "this is STDERR..."&lt;BR /&gt;ls -l &amp;gt; ${TMP}&lt;BR /&gt;cat ${TMP} &amp;gt;&amp;amp;4&lt;BR /&gt;cat ${TMP} &amp;gt;&amp;gt; ${LOG}&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 17 Apr 2009 16:53:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170285#M681963</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-17T16:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: LOGGING OUTPUT</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170286#M681964</link>
      <description>James, Thanks.. I am going to run it through cron tonight and debug if anything comes up.. Thanks again.. Rex</description>
      <pubDate>Fri, 17 Apr 2009 16:55:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/logging-output/m-p/5170286#M681964</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2009-04-17T16:55:43Z</dc:date>
    </item>
  </channel>
</rss>

