I am trying to find the load on a range of nodes in a cluster.
I would like to store the uptime from each node in an array I can
create aggregate statistics about the system uptime.
When I rsh the uptime command to each node without the background
operator “&” rsh returns the output of uptime, via command
substitution,
to an array member. I would prefer to have each rsh uptime
call to be in the background (i.e. called with & at the end) so that I
can asynchronously scan the performance of the system. However, when
I include the &, the output from the rsh command is not saved in the
array.
I have tried to put a sleep command in the script to see if a delay
would help,
but it had no effect.
Does anyone have a hint as to how I can capture the output from a
background rsh command? I have included a code snippet below.
Thanks,
Tony
------------------code snippet----------------------------------------
# find the load for each node asynchronously
i=0
while [ $i -lt $count ]
do
# this rsh call returns output
uptimes[$i]=$(rsh ${node_names[$i]} uptime)
# this rsh call in the background does not save output
# uptimes[$i]=$(rsh ${node_names[$i]} uptime) &
let "i +=1"
done
# sleep for 5 seconds to let everyone reply
sleep 5s
# print the load for each node
i=0
while [ $i -lt $count ]
do
echo "node ${node_names[$i]} ${uptimes[$i]}"
let "i +=1"
done