0

Hi guys I need some help, I wrote a script to connect to multiple ssh hosts but the script only work with the first IP the other ones didn't change. Here is my script:

#!/bin/bash
HOSTS="192.168.120.237 192.168.120.238 192.168.120.239"
USER=root

# Conectar a cada una de las IP
for host in $HOSTS; do 
  ssh "$USER@$HOSTS" 'bash -s arg' < /home/soulfly/Escritorio/neo1isla1.sh
done 
  • $HOSTS is a string, but you're using it (well, trying to use it) as an array. My Bash knowledge is limited, but I don't think it'll work like that. – ceejayoz Sep 11 '17 at 23:54
  • @ceejayoz bash will split a string in a loop like that using the internal field separator ($IFS). So a string will be broken up. Try running var='one two three four' ; for a in $var ; do echo "- $a" ; done – Zoredache Sep 14 '17 at 19:28
2

Try ssh "$USER@$host" instead of $HOSTS. The $HOSTS contains the list of all the addresses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.