<?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: Asynchronous command execution in a korn shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313839#M642010</link>
    <description>&lt;P&gt;That certainly would work, it's just kind of annoying to remember to have to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I can see cases where the function might be called interactively from the command line.&amp;nbsp; Again, while it would work to remember to "set +m" before use, it would get old quickly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The better solution, if possible, is figuring out how to turn off monitoring inside the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2011 19:56:41 GMT</pubDate>
    <dc:creator>Kris_Knigga</dc:creator>
    <dc:date>2011-08-26T19:56:41Z</dc:date>
    <item>
      <title>Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313815#M642007</link>
      <description>&lt;P&gt;I'm writing a little script (a function that gets sourced into the current shell, actually) that calls a couple of commands asynchronously (command &amp;amp;).&amp;nbsp; The script works fine, but I can't figure out how to suppress the job control information that gets printed to the terminal due to the asynchronous command﻿ calls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt;$ gethostbyalc ai dev
[1]     27621
[2]     27622
devg0d41
[2] +  Done                    gethostbyalc ai dev﻿
[1] +  Done                    gethostbyalc ai dev﻿
$&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I figured out that the first lines that print the PID when the commands get backgrounded are going to stderr, so that's pretty easy to get rid of.&amp;nbsp; The "done" lines, however, are being a little more stubborn.&amp;nbsp; I figured out that if I turn off ksh's monitor mode with "set +m" before I run the function that the "done" lines go away.&amp;nbsp; However, putting "set +m" in the function doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example turning monitoring off before calling the function (works):&lt;/P&gt;&lt;PRE&gt;$ set -x
$ set +m
+ set +m
$ gethostbyalc ai dev
+ gethostbyalc ai dev
+ OPTS=
+ APP=ai
+ LCYCLE=dev
+ + date +%Y%m%d%H%M%S
APP_FIFO=/tmp/app_list_fifo.20110826142834
+ + date +%Y%m%d%H%M%S
LCYCLE_FIFO=/tmp/lcycle_list_fifo.20110826142834
+ mkfifo /tmp/app_list_fifo.20110826142834
+ mkfifo /tmp/lcycle_list_fifo.20110826142834
+ exec
+ 3&amp;gt;&amp;amp; 2
+ exec
+ 2&amp;gt; /dev/null
devg0d41
+ exec
+ + rm /tmp/app_list_fifo.20110826142834
+ rm /tmp/lcycle_list_fifo.20110826142834
$&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example turning monitoring off inside the function (doesn't work):&lt;/P&gt;&lt;PRE&gt;$ set -x
$ gethostbyalc ai dev
+ gethostbyalc ai dev
+ set +m
+ OPTS=
+ APP=ai
+ LCYCLE=dev
+ + date +%Y%m%d%H%M%S
APP_FIFO=/tmp/app_list_fifo.20110826143118
+ + date +%Y%m%d%H%M%S
LCYCLE_FIFO=/tmp/lcycle_list_fifo.20110826143118
+ mkfifo /tmp/app_list_fifo.20110826143118
+ mkfifo /tmp/lcycle_list_fifo.20110826143118
+ exec
+ 3&amp;gt;&amp;amp; 2
+ exec
+ 2&amp;gt; /dev/null
devg0d41
+ exec
+ + rm /tmp/app_list_fifo.20110826143118
+ rm /tmp/lcycle_list_fifo.20110826143118
+ set -m
[2] +  Done                    gethostbyalc ai dev
[1] +  Done                    gethostbyalc ai dev
$&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas how to kill that output?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 19:35:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313815#M642007</guid>
      <dc:creator>Kris_Knigga</dc:creator>
      <dc:date>2011-08-26T19:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313825#M642008</link>
      <description>&lt;P&gt;Full function source:&lt;/P&gt;&lt;PRE&gt;gethostbyalc ()
{
        set +m
        OPTS=$3
        APP=$1
        LCYCLE=$2

        APP_FIFO="/tmp/app_list_fifo.$(date +'%Y%m%d%H%M%S')"
        LCYCLE_FIFO="/tmp/lcycle_list_fifo.$(date +'%Y%m%d%H%M%S')"

        mkfifo ${APP_FIFO}
        mkfifo ${LCYCLE_FIFO}

        exec 3&amp;gt;&amp;amp;2
        exec 2&amp;gt;/dev/null

        gethostbyapp $1 &amp;gt; ${APP_FIFO} &amp;amp;
        gethostbylcycle $2 &amp;gt; ${LCYCLE_FIFO} &amp;amp;

        case ${OPTS} in
                "-w")
                        comm -12 ${APP_FIFO} ${LCYCLE_FIFO} | awk 'BEGIN{ ORS=" " }{ print }'
                        echo
                        ;;

                *)
                        comm -12 ${APP_FIFO} ${LCYCLE_FIFO}
                        ;;
        esac

        wait

        exec 2&amp;gt;&amp;amp;3
        exec 3&amp;gt;&amp;amp;-

        rm ${APP_FIFO}
        rm ${LCYCLE_FIFO}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 19:40:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313825#M642008</guid>
      <dc:creator>Kris_Knigga</dc:creator>
      <dc:date>2011-08-26T19:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313831#M642009</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@mkdlxk wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;I figured out that the first lines that print the PID when the commands get backgrounded are going to stderr, so that's pretty easy to get rid of.&amp;nbsp; The "done" lines, however, are being a little more stubborn.&amp;nbsp; I figured out that if I turn off ksh's monitor mode with "set +m" before I run the function that the "done" lines go away.&amp;nbsp; However, putting "set +m" in the function doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, what's wrong with doing the 'set +m' in the calling script, before you source the file containing the function you want to run in the background?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 19:50:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313831#M642009</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-26T19:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313839#M642010</link>
      <description>&lt;P&gt;That certainly would work, it's just kind of annoying to remember to have to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I can see cases where the function might be called interactively from the command line.&amp;nbsp; Again, while it would work to remember to "set +m" before use, it would get old quickly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The better solution, if possible, is figuring out how to turn off monitoring inside the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 19:56:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313839#M642010</guid>
      <dc:creator>Kris_Knigga</dc:creator>
      <dc:date>2011-08-26T19:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313885#M642011</link>
      <description>&lt;P&gt;&amp;gt;The better solution is figuring out how to turn off monitoring inside the function.﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or convert it from a function to a separate script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the issue is that when the function returns, it resets +m.&amp;nbsp; (I've had to add "set -x" to each individual function.)&lt;/P&gt;&lt;P&gt;And moving it to a separate script may fail the same way if the background processes still haven't finished before it returns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could always put a sleep there. :-)&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 21:20:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5313885#M642011</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-08-26T21:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5315587#M642012</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/22676"&gt;@Dennis Handly&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&amp;gt;...may fail the same way if the background processes still haven't finished before it returns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could always put a sleep there. :-)&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;I was hoping the wait would take care of any such issues, but apparently not.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2011 13:48:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5315587#M642012</guid>
      <dc:creator>Kris_Knigga</dc:creator>
      <dc:date>2011-08-29T13:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Asynchronous command execution in a korn shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5326265#M642013</link>
      <description>&lt;P&gt;Unfortunately, the best answer I could come up with was to do away with the fancy named pipes and just use temporary files.&amp;nbsp; It does away with the need to background any processes and thusly eliminates unwanted output.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2011 20:25:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/asynchronous-command-execution-in-a-korn-shell-script/m-p/5326265#M642013</guid>
      <dc:creator>Kris_Knigga</dc:creator>
      <dc:date>2011-09-08T20:25:50Z</dc:date>
    </item>
  </channel>
</rss>

