For practising reasons Im trying the following script :
#!/bin/bash
NUM_OF_SERVERS=(server1 server2)
SSH_USERNAME=root
SSH_PASSWORD=password
version=$(cat /etc/redhat-release)
for HOST in ${NUM_OF_SERVERS[@]};
do /usr/bin/sshpass -p $SSH_PASSWORD ssh $SSH_USERNAME@$HOST echo "$version"
echo "The software version for ${NUM_OF_SERVERS[0]} is $version"
echo "The software version for ${NUM_OF_SERVERS[1]} is $version"
done
and the output :
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `echo CentOS Linux release 7.4.1708 (Core) '
The software version for server1 is CentOS Linux release 7.4.1708 (Core)
The software version for server2 is CentOS Linux release 7.4.1708 (Core)
The software version for server1 is CentOS Linux release 7.4.1708 (Core)
The software version for server2 is CentOS Linux release 7.4.1708 (Core)
Why this syntax error arises and why the loop occurs 4 times instead of 2 ?
Any help would be appreciated.