Bash: How to copy a file to multiple SSH servers all of which are specified in a list text file?
If you want to stay in bash-only domain:
while read server
scp thisfile.sh $server:/some/location
ssh $server /some/location/thisfile.sh
done < servers.txt
This will prompt execute one work at a time, and ask you for authentication when needed
Related videos on Youtube
user3125996
Updated on September 18, 2022Comments
-
user3125996 over 1 year
I have a file (lets say "thisfile.sh" for example) I would like to copy to multiple servers (of which some may require password authentication) at once upon launching my bash file, presumedly with SCP. All the server addresses are written one line at a time in a text document, lets say the file's called "ServerList", for example:
[email protected] [email protected] [email protected] [...]
How can I achieve this?
Edit: I thought about this a little more, and I'd still like to get this done with bash as a starter, I'll use an alternative a little later. How'd I suppose I'd get it done is by using the SCP copy command, and a variable in place of my destination, a little something like this scp myfile $Server:~/myfile. This way, I'm pretty sure I will need to use a Loop of some sort, so it would go through all the lines as I copy it.
-
Hewbot almost 9 yearsDo you want to write the passwords manually? Is the destiny directory always the same?
-
-
Hewbot almost 9 yearsI just deleted my answer since yours is the same but more complete ;)