<?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: Shell script timeout in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748793#M656325</link>
    <description>&lt;!--!*#--&gt;
&lt;P&gt;When you did a Forum search for keywords&lt;BR /&gt;like, say,&lt;BR /&gt;shell script timeout&lt;BR /&gt;did you find nothing which might be useful?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h30499.www3.hp.com/t5/Languages-and-Scripting/how-to-set-time-outs-for-commands-in-a-script/m-p/5041233#M36021" target="_blank"&gt;http://h30499.www3.hp.com/t5/Languages-and-Scripting/how-to-set-time-outs-for-commands-in-a-script/m-p/5041233#M36021&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2011 19:02:13 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2011-08-08T19:02:13Z</dc:date>
    <item>
      <title>Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748790#M656322</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I have a script that sometimes has the tenancy to hang on certain servers.  The script has two functions that it executes.  Is there anyway to make it so that the script or functions in the script timeout after a certain time limit is reached?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!</description>
      <pubDate>Fri, 04 Feb 2011 20:15:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748790#M656322</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2011-02-04T20:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748791#M656323</link>
      <description>&lt;P&gt;Hello Patrick,&lt;BR /&gt;&lt;BR /&gt;What functions you are calling ,we have "-m" &lt;BR /&gt;time out switch for ping.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h30499.www3.hp.com/t5/General/how-to-set-timeout-in-shell-script/m-p/3351662#M99224" target="_blank"&gt;http://h30499.www3.hp.com/t5/General/how-to-set-timeout-in-shell-script/m-p/3351662#M99224&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Manix&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2011 21:06:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748791#M656323</guid>
      <dc:creator>Manix</dc:creator>
      <dc:date>2011-09-29T21:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748792#M656324</link>
      <description>Custom functions.</description>
      <pubDate>Fri, 04 Feb 2011 21:05:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748792#M656324</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2011-02-04T21:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748793#M656325</link>
      <description>&lt;!--!*#--&gt;
&lt;P&gt;When you did a Forum search for keywords&lt;BR /&gt;like, say,&lt;BR /&gt;shell script timeout&lt;BR /&gt;did you find nothing which might be useful?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h30499.www3.hp.com/t5/Languages-and-Scripting/how-to-set-time-outs-for-commands-in-a-script/m-p/5041233#M36021" target="_blank"&gt;http://h30499.www3.hp.com/t5/Languages-and-Scripting/how-to-set-time-outs-for-commands-in-a-script/m-p/5041233#M36021&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2011 19:02:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748793#M656325</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-08-08T19:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748794#M656326</link>
      <description>&lt;!--!*#--&gt;Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;One way would be to fork() a process to monitor a part of itself.  In a pure shell script we can emulate that by running a piece (a function or subroutine) in the background.&lt;BR /&gt;&lt;BR /&gt;Here's a working example of what I mean:&lt;BR /&gt;&lt;BR /&gt;# cat ./monitor&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;typeset MAXSEC=10&lt;BR /&gt;typeset TIME_0=${SECONDS}&lt;BR /&gt;function do_work&lt;BR /&gt;{&lt;BR /&gt;    while true&lt;BR /&gt;    do&lt;BR /&gt;        date&lt;BR /&gt;        [ ! -z "$1" ] &amp;amp;&amp;amp; break #...to fake a fast execution...&lt;BR /&gt;        sleep 1                #...emulates work...&lt;BR /&gt;    done&lt;BR /&gt;    echo "...finished..."&lt;BR /&gt;}&lt;BR /&gt;do_work $1 &amp;amp;&lt;BR /&gt;WORKER=$!&lt;BR /&gt;while [ "$((${SECONDS}-${TIME_0}))" -le "${MAXSEC}" ]&lt;BR /&gt;do&lt;BR /&gt;    sleep 1 #...don't buzz processor needlessly...&lt;BR /&gt;    kill -0 ${WORKER} 2&amp;gt;/dev/null&lt;BR /&gt;    [ $? -ne 0 ] &amp;amp;&amp;amp; exit 0&lt;BR /&gt;done&lt;BR /&gt;echo "Time Limit exceeded"&lt;BR /&gt;kill ${WORKER} 2&amp;gt;/dev/null&lt;BR /&gt;exit 1&lt;BR /&gt;&lt;BR /&gt;...to see how this works, run the script two ways:&lt;BR /&gt;&lt;BR /&gt;# ./monitor quick&lt;BR /&gt;&lt;BR /&gt;...and:&lt;BR /&gt;&lt;BR /&gt;# ./monitor&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Feb 2011 23:06:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748794#M656326</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-02-04T23:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748795#M656327</link>
      <description>Maybe I used the wrong key words.</description>
      <pubDate>Fri, 04 Feb 2011 23:07:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748795#M656327</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2011-02-04T23:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748796#M656328</link>
      <description>I never thought of doing it that way, and I appreciate the help!  The only issue I am running into is the fact that  I have two, so after the first one, the script is exiting.  I'm trying to figure out a way for that not to happen, but haven't gotten there yet.</description>
      <pubDate>Sat, 05 Feb 2011 01:47:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748796#M656328</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2011-02-05T01:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748797#M656329</link>
      <description>I may have just figured it out.  If I call the second function from the first, it seems to work.  Any drawbacks to this?</description>
      <pubDate>Sat, 05 Feb 2011 02:34:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748797#M656329</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2011-02-05T02:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748798#M656330</link>
      <description>&lt;!--!*#--&gt;Hi (again) Patrick:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The only issue I am running into is the fact that I have two, so after the first one, the script is exiting. &lt;BR /&gt;&lt;BR /&gt;Then consider doing something like this variation:&lt;BR /&gt;&lt;BR /&gt;# cat ./monitor&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset MAXSEC=10&lt;BR /&gt;function do_work&lt;BR /&gt;{&lt;BR /&gt;    typeset CMD=$1&lt;BR /&gt;    typeset ONE=$2&lt;BR /&gt;&lt;BR /&gt;    while true&lt;BR /&gt;    do&lt;BR /&gt;        eval "$1"&lt;BR /&gt;        [ ! -z "${ONE}" ] &amp;amp;&amp;amp; break #...to fake a fast execution...&lt;BR /&gt;        sleep 1                    #...emulates work...&lt;BR /&gt;    done&lt;BR /&gt;    echo "...finished..."&lt;BR /&gt;}&lt;BR /&gt;function monitor&lt;BR /&gt;{&lt;BR /&gt;    typeset WORKER=$!&lt;BR /&gt;    typeset TIME_0=${SECONDS}&lt;BR /&gt;    while [ "$((${SECONDS}-${TIME_0}))" -le "${MAXSEC}" ]&lt;BR /&gt;    do&lt;BR /&gt;        sleep 1  #...don't buzz processor needlessly...&lt;BR /&gt;        kill -0 ${WORKER} 2&amp;gt;/dev/null&lt;BR /&gt;        [ $? -ne 0 ] &amp;amp;&amp;amp; return 0&lt;BR /&gt;    done&lt;BR /&gt;    echo "Time Limit exceeded"&lt;BR /&gt;    kill ${WORKER} 2&amp;gt;/dev/null&lt;BR /&gt;    return 1&lt;BR /&gt;}&lt;BR /&gt;do_work "date"     $1 &amp;amp;&lt;BR /&gt;monitor &amp;amp;&amp;amp; echo "rc=$?" || echo "rc=$?"&lt;BR /&gt;do_work "uname -a" $1 &amp;amp;&lt;BR /&gt;monitor &amp;amp;&amp;amp; echo "rc=$?" || echo "rc=$?"&lt;BR /&gt;exit 0&lt;BR /&gt;#_end_&lt;BR /&gt;&lt;BR /&gt;...This is easily amended to pass the MAXSEC value as an argument to allow different processes to be bounded by different time limits.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sat, 05 Feb 2011 13:47:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748798#M656330</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-02-05T13:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script timeout</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748799#M656331</link>
      <description>&lt;!--!*#--&gt;Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;Depending on the nature of your processes, and whether or not you care about partial output, you could wrap your script with a small Perl wrapper and leverage Perl's signal handling abilities.&lt;BR /&gt;&lt;BR /&gt;Consider a ahell script called "watch.sh:&lt;BR /&gt;&lt;BR /&gt;# cat ./watch.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;X=0&lt;BR /&gt;for N in 1 2 3 4 5&lt;BR /&gt;do&lt;BR /&gt;    date&lt;BR /&gt;    sleep 1&lt;BR /&gt;done&lt;BR /&gt;echo "...finished!"&lt;BR /&gt;&lt;BR /&gt;...Now create a wrapper thusly:&lt;BR /&gt;&lt;BR /&gt;# cat ./watch.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $command=shift or die "Command or script expected\n";&lt;BR /&gt;my $timeout=shift || 3;&lt;BR /&gt;$SIG{ALRM}=sub{die "Timeout!\n"};&lt;BR /&gt;alarm $timeout;&lt;BR /&gt;my @results=`$command`;&lt;BR /&gt;print @results;&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...The wrapper expects to be passed the name of the process to be executed as it's first argument.  An optional second argument defines the timeout.  This value defaults to 3-seconds in the above variation.  To see the script in action, try:&lt;BR /&gt;&lt;BR /&gt;# ./watch.pl ./watch.sh&lt;BR /&gt;&lt;BR /&gt;...versus:&lt;BR /&gt;&lt;BR /&gt;# ./watch.pl ./watch.sh 10&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 05 Feb 2011 15:08:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-timeout/m-p/4748799#M656331</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-02-05T15:08:31Z</dc:date>
    </item>
  </channel>
</rss>

