I am trying to use a FOR loop to iterate over IP addresses (in a bash array), logs in, runs a script and then exits. The array is called ${INSTANCE_IPS[@]}. The following code doesn't work though, as expect
doesn't seem to be able to accept the variable $instance.
for instance in ${INSTANCE_IPS[@]}
do
echo $instance
/usr/bin/expect -c '
spawn ssh root@$instance;
expect "?assword: ";
send "<password>\r";
expect "# ";
send ". /usr/local/bin/bootstrap.sh\r";
expect "# ";
send "exit\r" '
done
However, expect
complains with:
can't read "instance": no such variable
while executing
"spawn ssh root@$instance"
There is another question on stackoverflow located here, that uses environmental variables to achieve this, however it doesn't allow me to iterate through different IP addresses like I can in an array.
Any help is appreciated.
Cheers