Last active
April 18, 2016 05:14
-
-
Save psachin/35b4c85688dd9f23a800985766dbd237 to your computer and use it in GitHub Desktop.
Objective is to ssh IPaddr in an array and use the consecutive IPaddr in the conf file. It should complete one full loop. See example in the comment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Objective is to ssh IPaddr in an array and use the consecutive IPaddr in the conf file. | |
# Something like this: | |
# ssh 192.168.0.1 -C "echo 192.168.0.2 >> ~/ips" | |
# ssh 192.168.0.2 -C "echo 192.168.0.3 >> ~/ips" | |
# ssh 192.168.0.3 -C "echo 192.168.0.4 >> ~/ips" | |
# ssh 192.168.0.4 -C "echo 192.168.0.1 >> ~/ips" | |
x="192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4" | |
arr=($(echo $x | tr " " "\n")) | |
len=${#arr[@]} | |
for (( i=0; i<${len}; i++ )); | |
do | |
if [ $i -lt $(( $len - 1 )) ]; | |
then | |
SSH_IP=${arr[$i]} | |
CONFIG_IP=${arr[$i+1]} | |
else | |
SSH_IP=${arr[$i]} | |
CONFIG_IP=${arr[0]} | |
fi | |
ssh ${SSH_IP} -C "echo ${CONFIG_IP} >> ~/ips" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment