<?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 ksh logging in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170293#M718112</link>
    <description>I am writing a script that is being executed by roots crontab and sends the output to a log.&lt;BR /&gt; &lt;BR /&gt;0 0 * * 6 su  back -c /home/back/scripts/backup/backup_db.sh &amp;gt; /home/back/log/backup_db.log.`date +\%j`&lt;BR /&gt; &lt;BR /&gt;My problem is is that the script is in ksh, this script call 3 other scripts.&lt;BR /&gt;&lt;BR /&gt;I would like to have all the output emailed to me, (and later, only email if I get an error from any of the scripts that ran).&lt;BR /&gt;How do I set logging in backup_db.sh and at the end mail the file.&lt;BR /&gt;&lt;BR /&gt;I am sure there is a better way to do this, but any help would be appreciated.&lt;BR /&gt;&lt;BR /&gt;All the scripts are done in ksh, yes, I would like to go to perl, but, not at this time...</description>
    <pubDate>Wed, 21 Jan 2004 15:50:56 GMT</pubDate>
    <dc:creator>Ratzie</dc:creator>
    <dc:date>2004-01-21T15:50:56Z</dc:date>
    <item>
      <title>ksh logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170293#M718112</link>
      <description>I am writing a script that is being executed by roots crontab and sends the output to a log.&lt;BR /&gt; &lt;BR /&gt;0 0 * * 6 su  back -c /home/back/scripts/backup/backup_db.sh &amp;gt; /home/back/log/backup_db.log.`date +\%j`&lt;BR /&gt; &lt;BR /&gt;My problem is is that the script is in ksh, this script call 3 other scripts.&lt;BR /&gt;&lt;BR /&gt;I would like to have all the output emailed to me, (and later, only email if I get an error from any of the scripts that ran).&lt;BR /&gt;How do I set logging in backup_db.sh and at the end mail the file.&lt;BR /&gt;&lt;BR /&gt;I am sure there is a better way to do this, but any help would be appreciated.&lt;BR /&gt;&lt;BR /&gt;All the scripts are done in ksh, yes, I would like to go to perl, but, not at this time...</description>
      <pubDate>Wed, 21 Jan 2004 15:50:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170293#M718112</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-01-21T15:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: ksh logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170294#M718113</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;This is one of the solutions.&lt;BR /&gt;&lt;BR /&gt;0 0 * * 6 su back -c /home/back/scripts/backup/backup_db.sh &amp;gt; /home/back/log/backup_db.log.`date +\%j` 2&amp;gt;&amp;amp;1; mailx -s "Details of backup" your_id@yourdomain.com &amp;lt; /home/back/log/backup_db.log.`date +\%j`&lt;BR /&gt;&lt;BR /&gt;The above will mail all the details.&lt;BR /&gt;&lt;BR /&gt;Later for only error log&lt;BR /&gt;&lt;BR /&gt;0 0 * * 6 su back -c /home/back/scripts/backup/backup_db.sh &amp;gt; /home/back/log/backup_db.log.`date +\%j` 2&amp;gt;/home/back/log/backup_db.err.`date +\%j`; mailx -s "Details of backup" your_id@yourdomain.com &amp;lt; /home/back/log/backup_db.err.`date +\%j`&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Jan 2004 16:05:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170294#M718113</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-01-21T16:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: ksh logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170295#M718114</link>
      <description>The key to what you are trying to do is the "exec" command.&lt;BR /&gt;&lt;BR /&gt;For example,&lt;BR /&gt;exec 1&amp;gt;/var/tmp/mylog 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;ls&lt;BR /&gt;echo "Test"&lt;BR /&gt;ls Badfile&lt;BR /&gt;&lt;BR /&gt;will combine stdout and stderr onto /var/tmp/mylog. Put the exec at the top of your script and stdout/stderr will be sent to the file. At the end of your script test to see whether mylog is non-empty and if so mail the contents of that file and then remove it.&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Jan 2004 16:13:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170295#M718114</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-01-21T16:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: ksh logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170296#M718115</link>
      <description>There isn't a single solution to your question. cron will automatically mail you a copy of all stdout and stderr from your script(s). Now since you redirected stdout into the /home/back/log directory, the email is limited to stderr. ksh is not a problem, just standard shell programming techniques. Just use tee in your cron job:&lt;BR /&gt; &lt;BR /&gt;su back -c /home/back/scripts/backup/backup_db.sh | tee /home/back/log/backup_db.log.`date +\%j`&lt;BR /&gt; &lt;BR /&gt;What tee does in this context is to write stdout to the file (just like before) but also echo everything written to the file to stdout so it will be emailed. As far as all output versus only errors, you control this in your script(s). Set a variable, perhaps ERRORONLY to be tested and echo or print information only when it is false. To test everything, set ERRORONLY to true and you should see only errors (that is, text sent to stderr in your script). Set it to false and you'll see every echo and print sent to stdout.&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Jan 2004 16:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170296#M718115</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-01-21T16:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: ksh logging</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170297#M718116</link>
      <description>I am really curious why you arent using posix... HPUX posix shell is very good and IMHO superior to KSH.</description>
      <pubDate>Wed, 21 Jan 2004 16:20:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-logging/m-p/3170297#M718116</guid>
      <dc:creator>Todd McDaniel_1</dc:creator>
      <dc:date>2004-01-21T16:20:23Z</dc:date>
    </item>
  </channel>
</rss>

