<?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 Background connections in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678308#M658616</link>
    <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;there are some task, that need to be done on about 500 servers. When it's done one-by-one, it take considerable time. I was trying to start each connection in background and wait for results with 'wait pid'. It works well, this way. But if I want also catch output from each connection and display it, in order, they have been started, it doesn't work. I wrote this script:&lt;BR /&gt;------------------------------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;pipedir=~/myscript$$&lt;BR /&gt;mkdir $pipedir&lt;BR /&gt;processes_max=200&lt;BR /&gt;processes_toread=100&lt;BR /&gt;servers_started=0&lt;BR /&gt;servers_read=0&lt;BR /&gt;processes_running=0&lt;BR /&gt;&lt;BR /&gt;# Get servers&lt;BR /&gt;i=0&lt;BR /&gt;for srv in $(get_servers for_testing);do&lt;BR /&gt;   server_list[$i]=$srv&lt;BR /&gt;   let i++&lt;BR /&gt;done&lt;BR /&gt;servers_count=${#server_list[*]}&lt;BR /&gt;&lt;BR /&gt;# Start processess in background&lt;BR /&gt;while [ $servers_read -lt $servers_count ] ;do&lt;BR /&gt;   server_actual=$servers_started&lt;BR /&gt;   while [ $processes_running -lt $processes_max ] &amp;amp;&amp;amp; [ $server_actual -lt $servers_count ] ; do&lt;BR /&gt;      mkfifo $pipedir/$server_actual&lt;BR /&gt;      ssh -q ${server_list[$server_actual]} "PATH=\$PATH:/usr/bin:/usr/sbin:/usr/local/bin ;sudo uname" &amp;gt; $pipedir/$server_actual &amp;amp;&lt;BR /&gt;            process_list[$server_actual]=$!&lt;BR /&gt;      let server_actual++&lt;BR /&gt;      let processes_running++&lt;BR /&gt;      let servers_started++&lt;BR /&gt;   done&lt;BR /&gt;   # Show results&lt;BR /&gt;   server_actual=$servers_read&lt;BR /&gt;   i=0&lt;BR /&gt;   while [ $i -lt $processes_toread ] &amp;amp;&amp;amp; [ $server_actual -lt $servers_started ] ; do&lt;BR /&gt;      if [ $server_actual -eq $servers_count ]; then&lt;BR /&gt;         break 2&lt;BR /&gt;      fi&lt;BR /&gt;      echo -n ${server_list[$server_actual]}:&lt;BR /&gt;      cat &amp;lt;$pipedir/$server_actual&lt;BR /&gt;      wait ${process_list[$server_actual]}&lt;BR /&gt;      rm $pipedir/$server_actual&lt;BR /&gt;      let i++&lt;BR /&gt;      let processes_running--&lt;BR /&gt;      let server_actual++&lt;BR /&gt;      let servers_read++&lt;BR /&gt;   done&lt;BR /&gt;done&lt;BR /&gt;rmdir $pipedir&lt;BR /&gt;exit 0&lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;It use named pipe to send output from each connection to. Problem is, that 'ssh' program is blocked until other side of pipe is open 'cat pipe'. So it's working almost, like one-by-one proceeding.&lt;BR /&gt;I tried also to store result from background process in to variable, but it either store empty string (immediate output after process go to background), or it waits for process finish and then it assign the output to variable. It would be more simple, to just let each process to write it's output on stdout as it finish. But it'd be mess. I need to have output aranged in form:&lt;BR /&gt;servername1:output1&lt;BR /&gt;servername2:output2&lt;BR /&gt;Do somebody has some solution? &lt;BR /&gt;Thanks.&lt;BR /&gt;    Viliam Kocinsky</description>
    <pubDate>Mon, 23 Aug 2010 15:23:44 GMT</pubDate>
    <dc:creator>Viliam Kocinsky</dc:creator>
    <dc:date>2010-08-23T15:23:44Z</dc:date>
    <item>
      <title>Background connections</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678308#M658616</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;there are some task, that need to be done on about 500 servers. When it's done one-by-one, it take considerable time. I was trying to start each connection in background and wait for results with 'wait pid'. It works well, this way. But if I want also catch output from each connection and display it, in order, they have been started, it doesn't work. I wrote this script:&lt;BR /&gt;------------------------------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;pipedir=~/myscript$$&lt;BR /&gt;mkdir $pipedir&lt;BR /&gt;processes_max=200&lt;BR /&gt;processes_toread=100&lt;BR /&gt;servers_started=0&lt;BR /&gt;servers_read=0&lt;BR /&gt;processes_running=0&lt;BR /&gt;&lt;BR /&gt;# Get servers&lt;BR /&gt;i=0&lt;BR /&gt;for srv in $(get_servers for_testing);do&lt;BR /&gt;   server_list[$i]=$srv&lt;BR /&gt;   let i++&lt;BR /&gt;done&lt;BR /&gt;servers_count=${#server_list[*]}&lt;BR /&gt;&lt;BR /&gt;# Start processess in background&lt;BR /&gt;while [ $servers_read -lt $servers_count ] ;do&lt;BR /&gt;   server_actual=$servers_started&lt;BR /&gt;   while [ $processes_running -lt $processes_max ] &amp;amp;&amp;amp; [ $server_actual -lt $servers_count ] ; do&lt;BR /&gt;      mkfifo $pipedir/$server_actual&lt;BR /&gt;      ssh -q ${server_list[$server_actual]} "PATH=\$PATH:/usr/bin:/usr/sbin:/usr/local/bin ;sudo uname" &amp;gt; $pipedir/$server_actual &amp;amp;&lt;BR /&gt;            process_list[$server_actual]=$!&lt;BR /&gt;      let server_actual++&lt;BR /&gt;      let processes_running++&lt;BR /&gt;      let servers_started++&lt;BR /&gt;   done&lt;BR /&gt;   # Show results&lt;BR /&gt;   server_actual=$servers_read&lt;BR /&gt;   i=0&lt;BR /&gt;   while [ $i -lt $processes_toread ] &amp;amp;&amp;amp; [ $server_actual -lt $servers_started ] ; do&lt;BR /&gt;      if [ $server_actual -eq $servers_count ]; then&lt;BR /&gt;         break 2&lt;BR /&gt;      fi&lt;BR /&gt;      echo -n ${server_list[$server_actual]}:&lt;BR /&gt;      cat &amp;lt;$pipedir/$server_actual&lt;BR /&gt;      wait ${process_list[$server_actual]}&lt;BR /&gt;      rm $pipedir/$server_actual&lt;BR /&gt;      let i++&lt;BR /&gt;      let processes_running--&lt;BR /&gt;      let server_actual++&lt;BR /&gt;      let servers_read++&lt;BR /&gt;   done&lt;BR /&gt;done&lt;BR /&gt;rmdir $pipedir&lt;BR /&gt;exit 0&lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;It use named pipe to send output from each connection to. Problem is, that 'ssh' program is blocked until other side of pipe is open 'cat pipe'. So it's working almost, like one-by-one proceeding.&lt;BR /&gt;I tried also to store result from background process in to variable, but it either store empty string (immediate output after process go to background), or it waits for process finish and then it assign the output to variable. It would be more simple, to just let each process to write it's output on stdout as it finish. But it'd be mess. I need to have output aranged in form:&lt;BR /&gt;servername1:output1&lt;BR /&gt;servername2:output2&lt;BR /&gt;Do somebody has some solution? &lt;BR /&gt;Thanks.&lt;BR /&gt;    Viliam Kocinsky</description>
      <pubDate>Mon, 23 Aug 2010 15:23:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678308#M658616</guid>
      <dc:creator>Viliam Kocinsky</dc:creator>
      <dc:date>2010-08-23T15:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Background connections</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678309#M658617</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;Lets say I had a list of servers called list&lt;BR /&gt;&lt;BR /&gt;while read -r hostname&lt;BR /&gt;do&lt;BR /&gt;   echo "run command"&lt;BR /&gt;   ssh -f $hostname &lt;COMMAND&gt;&lt;BR /&gt;done &amp;lt; list&lt;BR /&gt;&lt;BR /&gt;This would of course require a public ssh key be placed on the server.&lt;BR /&gt;&lt;BR /&gt;I've used -f to run ssh commands in batch mode with success.&lt;BR /&gt;&lt;BR /&gt;SEP&lt;/COMMAND&gt;</description>
      <pubDate>Mon, 23 Aug 2010 15:30:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678309#M658617</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2010-08-23T15:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Background connections</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678310#M658618</link>
      <description>&lt;!--!*#--&gt;Hi Viliam:&lt;BR /&gt;&lt;BR /&gt;Here's a prototype that collects the output from a background process into a file.  Each line of the file begins with an ordinal process number (1..n) which allows you to sort the results back into the order in which the processes were started.&lt;BR /&gt;&lt;BR /&gt;# cat ./probe&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i i=0&lt;BR /&gt;typeset    SERVERS=/tmp/servers&lt;BR /&gt;typeset    RESULTS=/tmp/results.log&lt;BR /&gt;for SERVER in $(&amp;lt; ${SERVERS})&lt;BR /&gt;do&lt;BR /&gt;    i=$((i+1))&lt;BR /&gt;    ssh -n ${SERVER} "{ echo ${i};echo ${SERVER};sleep 10;date;uname -a; }|xargs" &amp;gt;&amp;gt; /tmp/results.log &amp;amp;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...In this prototype, the one-line result per server consists of the server name; the date; and the server's 'uname' information --- all collected into one line of the output file and beginning with an ordinal process number.&lt;BR /&gt;&lt;BR /&gt;The ${SERVERS} input file simply has a server name; one per line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Aug 2010 19:25:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-connections/m-p/4678310#M658618</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-08-23T19:25:46Z</dc:date>
    </item>
  </channel>
</rss>

