Just some background, I have a file with 1000 servers in it new line delimted. I have to read them to an array the run about 5 commands over SSH. I have been using heredoc notation but that seems to fail. Currently I get an error saying the host isn't recognized.
IFS='\n' read -d '' -r -a my_arr < file
my_arr=()
for i in "${my_arr[@]}"; do
ssh "$1" bash -s << "EOF"
echo "making back up of some file"
cp /path/to/file /path/to/file.bak
exit
EOF
done
I get output that lists the first server but then all the ones in the array as well. I know that I am missing a redirect for STDIN that causes this.
Thanks for the help.
$iin your script, other than as the item being iterated over. Do you want$irather than$1?for i in "${my_arr[@]}"; do echo "$1"; donewould fail in the same way.declare -p my_arrto print its contents unambiguously, to answer the question of whether the array is in fact correctly populated.EOFis only honored as the end of a heredoc if not indented. If your real file isn't indented, the use only a four-space indent in your question to accurately reflect that, rather than the eight-space indent given here.