Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

rexec acts as break in ksh while loop?

SOLVED
Go to solution
Ryan Kogelheide
Frequent Advisor

rexec acts as break in ksh while loop?

This is probably a simple one. I have three ksh shell scripts. The first is a loop that scans a list of nodes using while and calls the second with the node as the parameter.

The second says if the node is hostname, execute the third shell script using ksh -c, otherwise execute it on the remote node using rexec.

The loop continues working until it reaches a remote node. It executes the script on the remote node, but then the loop exits.
4 REPLIES
Steven Sim Kok Leong
Honored Contributor
Solution

Re: rexec acts as break in ksh while loop?

Hi,

Prefer a for loop to a while loop.

first.sh:

#!/sbin/sh
for node in `cat nodelist`
do
second.sh $node
if [ -e /tmp/foundit ]
then
rm -f /tmp/foundit
exit 0
fi
done

second.sh:

#!/sbin/sh
if [ "$1" != "`hostname`" ]
then
rexec $1 third.sh
touch /tmp/foundit
else
ksh -c third.sh
fi

Hope this helps. Regards.

Steven Sim Kok Leong
Email: steven@beepz.com. Homepage: https://www.beepz.com
Ryan Kogelheide
Frequent Advisor

Re: rexec acts as break in ksh while loop?

That seems to do the trick. Can you tell me why "for" works and "while" does not?
Robin Wakefield
Honored Contributor

Re: rexec acts as break in ksh while loop?

Hi Ryan,

With while loops, any remsh/rexec calls within the loop need to use the -n switch - here's the man entry to explain:

===================
By default, remsh reads its standard input and sends it to the remote command because remsh has no way to determine whether the remote command requires input. The -n option redirects standard input to remsh from /dev/null. This is useful when running a shell script containing a remsh command, since otherwise remsh may use input not intended for it.
===================

Because "while" uses read, but "for" doesn't, this hopefully explains the difference.

Rgds, Robin
Ryan Kogelheide
Frequent Advisor

Re: rexec acts as break in ksh while loop?

Woohoo!

That explains another problem I was having. (the -n)