<?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: flagging script failures in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839079#M939166</link>
    <description>in your crontab couldn't you just output your errors?&lt;BR /&gt;&lt;BR /&gt;00*** script 2&amp;gt; mail (etc....)&lt;BR /&gt;&lt;BR /&gt;I've never tried this... i was wondering if this would work?</description>
    <pubDate>Tue, 05 Nov 2002 18:00:36 GMT</pubDate>
    <dc:creator>John Meissner</dc:creator>
    <dc:date>2002-11-05T18:00:36Z</dc:date>
    <item>
      <title>flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839070#M939157</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;I have a cron job that executes daily and I'd like an email sent to a user if this job fails. Other than checking the return code in the cron log, what's the easiest way to do this?&lt;BR /&gt;&lt;BR /&gt;There are about half a dozen commands in the script so I could get the value of $? and check each line has worked but there nust be a better way.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Gary.</description>
      <pubDate>Tue, 05 Nov 2002 12:30:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839070#M939157</guid>
      <dc:creator>gary phipps</dc:creator>
      <dc:date>2002-11-05T12:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839071#M939158</link>
      <description>You need to write a better script that checks the result codes of each command that it calls. Indeed you may want to change the logic so that if a command fails then recovery action is taken or simply subsequent commands aren't run.&lt;BR /&gt;&lt;BR /&gt;The return code in the cron log is simply the code returned by the script. Depending on how that's written it may be the code returned from the last command run.&lt;BR /&gt;&lt;BR /&gt;If you post the cron script, I'd be able to give you some more information.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
      <pubDate>Tue, 05 Nov 2002 12:38:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839071#M939158</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2002-11-05T12:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839072#M939159</link>
      <description>Hi John,&lt;BR /&gt;&lt;BR /&gt;it's quite a simple script that extracts lines from a number of data files and concatenates them into another file.&lt;BR /&gt;I could check each command individually but I was wondering if there was a way to globally trap errors. Something like an "on error then goto" function.&lt;BR /&gt;I also wondered if there was a way to flag the fact that the cron job has failed. I could create another job that scans the cron log but I was hoping there was a simpler way.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Gary.</description>
      <pubDate>Tue, 05 Nov 2002 12:47:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839072#M939159</guid>
      <dc:creator>gary phipps</dc:creator>
      <dc:date>2002-11-05T12:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839073#M939160</link>
      <description>You'll have to check each individually, the shell doesn't have an 'on error' facility.&lt;BR /&gt;&lt;BR /&gt;As with most other things in UNIX though, there are many ways that you can code though. For instance, you can do...&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt;&lt;BR /&gt;if [[ ${?} -eq 0 ]];&lt;BR /&gt;then &lt;ACTION on="" success=""&gt;&lt;BR /&gt;&lt;BR /&gt;if &lt;COMMAND&gt;&lt;BR /&gt;then &lt;ACTION on="" success=""&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; &amp;amp;&amp;amp; &lt;SINGLE action="https://community.hpe.com/" on="" success=""&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt;&lt;BR /&gt;if [[ ${?} -ne 0 ]];&lt;BR /&gt;then &lt;ACTION on="" failure=""&gt;&lt;BR /&gt;&lt;BR /&gt;if ! &lt;COMMAND&gt;&lt;BR /&gt;then &lt;ACTION on="" failure=""&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; || &lt;SINGLE action="https://community.hpe.com/" on="" failure=""&gt;&lt;BR /&gt;&lt;BR /&gt;etc...&lt;BR /&gt;&lt;BR /&gt;The || construct can be useful with an error handling function, for example:-&lt;BR /&gt;&lt;BR /&gt;function failit {&lt;BR /&gt;commands here to send you a mail etc. Arguments can be supplied to the function to give additional information about the failure.&lt;BR /&gt;exit&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;command1 || failit "command1 failed"&lt;BR /&gt;&lt;BR /&gt;command2 || failit "command2 failed"&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John&lt;/SINGLE&gt;&lt;/COMMAND&gt;&lt;/ACTION&gt;&lt;/COMMAND&gt;&lt;/ACTION&gt;&lt;/COMMAND&gt;&lt;/SINGLE&gt;&lt;/COMMAND&gt;&lt;/ACTION&gt;&lt;/COMMAND&gt;&lt;/ACTION&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Tue, 05 Nov 2002 13:09:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839073#M939160</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2002-11-05T13:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839074#M939161</link>
      <description>Hi Gary,&lt;BR /&gt;&lt;BR /&gt;If you know the cronjob will return a non-zero code on error, then you could set your crontab entry to look like this:&lt;BR /&gt;&lt;BR /&gt;0 0 * * * yourscript || mailx -s "yourscript failed" first.last@company.com&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Tue, 05 Nov 2002 13:11:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839074#M939161</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2002-11-05T13:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839075#M939162</link>
      <description>On error? Theres a VB command I haven't heard for a while!&lt;BR /&gt;&lt;BR /&gt;Put the entire main portion inside a function; at each major step, increment a position counter variable and export it. When you reach an error, perform a 'return' or 'break'.&lt;BR /&gt;&lt;BR /&gt;Outside the function, test the value of the position counter; if it is not the final code (1 more than the variable for the last major step), display an error.&lt;BR /&gt;&lt;BR /&gt;POSIX Shell programming has restrictive features, but some of them can be useful if you think a little laterally.&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian &lt;BR /&gt;</description>
      <pubDate>Tue, 05 Nov 2002 13:18:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839075#M939162</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2002-11-05T13:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839076#M939163</link>
      <description>Hi&lt;BR /&gt;look at "man crontab":&lt;BR /&gt;&lt;BR /&gt;-----------------&lt;BR /&gt; WARNINGS&lt;BR /&gt;      Be sure to redirect the standard output and standard error from&lt;BR /&gt;      commands.  If this is not done, any generated standard output or&lt;BR /&gt;      standard error is mailed to the user.&lt;BR /&gt;&lt;BR /&gt;---------------&lt;BR /&gt;So cron sends mail by default if you don't use redirection:&lt;BR /&gt;&lt;BR /&gt;* * * * * command 1&amp;gt;/tmp/command.out&lt;BR /&gt;&lt;BR /&gt;means that standard-out is written to file and standard-error sends a mail to the user of the cron&lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Nov 2002 13:19:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839076#M939163</guid>
      <dc:creator>Christian Gebhardt</dc:creator>
      <dc:date>2002-11-05T13:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839077#M939164</link>
      <description>Thanks guys,&lt;BR /&gt;&lt;BR /&gt;I think I'll go with Robin's suggestion, putting "||" in crontab.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Gary.&lt;BR /&gt;&lt;BR /&gt;p.s. Ian, I was thinking DCL not VB!</description>
      <pubDate>Tue, 05 Nov 2002 14:21:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839077#M939164</guid>
      <dc:creator>gary phipps</dc:creator>
      <dc:date>2002-11-05T14:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839078#M939165</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Perhaps I come too late, but I just want to add that a 'on error' like functionnality really exists in Posix shell. I never used it because I don't find it 'clean' enough, but ...&lt;BR /&gt;&lt;BR /&gt;trap "echo error in script; exit 1" ERR&lt;BR /&gt;&lt;BR /&gt;manages a special trap to gives this message and exit 1 whenever a command returns a non zero exit code. See man sh-posix, trap command.&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 05 Nov 2002 15:39:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839078#M939165</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-11-05T15:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839079#M939166</link>
      <description>in your crontab couldn't you just output your errors?&lt;BR /&gt;&lt;BR /&gt;00*** script 2&amp;gt; mail (etc....)&lt;BR /&gt;&lt;BR /&gt;I've never tried this... i was wondering if this would work?</description>
      <pubDate>Tue, 05 Nov 2002 18:00:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839079#M939166</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-11-05T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: flagging script failures</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839080#M939167</link>
      <description>By default cron will send the stderr and stdout to the &lt;BR /&gt;user if they are no empty at the end of the job.&lt;BR /&gt;&lt;BR /&gt;If you make sure that errors result in output on stderr and&lt;BR /&gt;don't redirect it to /dev/null the error status will be &lt;BR /&gt;automatically mailed.&lt;BR /&gt;&lt;BR /&gt;The trick is to get it to someone usefull.  I use&lt;BR /&gt;procmail to look at the subject header and direct it &lt;BR /&gt;accordingly.  The redirects&lt;BR /&gt;are to alaises that contain&lt;BR /&gt;one or more people depending on the script.&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Nov 2002 17:27:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/flagging-script-failures/m-p/2839080#M939167</guid>
      <dc:creator>Bill Thorsteinson</dc:creator>
      <dc:date>2002-11-06T17:27:21Z</dc:date>
    </item>
  </channel>
</rss>

