Wednesday, November 12, 2008

linux:shell: broken 'while' loop

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'

1 comment:

ICS Cyber Security said...

Hi,
I have a signature field already in my document and I want to prompt the user to sign it. For instance, there are 100 pdfs with signature fields... I want to have a script run through VBA that opens all 100 PDDocs and prompts the user for 100 signatures so they dont have to go and open each one.
PDF signature

Locations of visitors to this page