When I do a while loop in which there is a command 'ssh', the while loop just goes only one iteration and quits. The problem is from 'ssh' read stdin so that 'while' cannot read anymore and stop afterwards, for example,
while read CompName
do
ssh $CompName 'ls'
echo "Done"
done <>
In the example, only one iteration is conducted (including the echo line). The solutions are provided by google searching. One is general one, I think. 1) Redirect ssh stdin by
< /dev/null ssh $CompName 'ls'
2) ssh-specified trick: use '-n':
ssh -n $CompName 'ls'
Showing posts with label break. Show all posts
Showing posts with label break. Show all posts
Wednesday, November 12, 2008
linux:shell: broken 'while' loop
Subscribe to:
Posts (Atom)
