Tuesday 16 November 2010

ssh in a loop

Runs the command 'ls' on several machines and stores the results in output.txt


while read host; do
echo "running on $host"
ssh -n $host "ls " >> output.txt;
done < boxes.txt


where boxes.txt is a file containing a list of machines to ssh to

advanced reading

Alternative:

for loop in {281..284}
do
echo "running on frread@nygeqgd0$loop.us.db.com"
ssh -n frread@nygeqgd0$loop.us.db.com "ls " >> output.txt;
done


2nd Alternative:

for loop in `seq 281 284`

more bash loops

No comments:

Post a Comment