So I have a list of servers with n length. I need to open a connection and edit a file and close it.
Here's what I currently have:
#!/bin/bash
server_list=(a b c d)
for i in "${server[@]}"; do ssh "${server[@]}"; cd /etc; cp file file.bak; perl -pi -i 's/find/replace/g' file; exit; done
The only issue I have is that I can't exit the ssh connection and move on to the next in the array. I have used the -n, -t and -T options to no avail.
Thanks.
scp file "${server[@]}/etc/"ssh "${server[@]}"is a distinct command fromcd /etc, and as your code is currently written,cd /etcwon't be run untilssh "${server[@]}"exits.