I have file called server.txt
Suppose it has below servers , there could be more servers server1 server2 server3 server4
how can I copy file (file.txt on all servers using scp command) at /tmp/ location .
I have file called server.txt
Suppose it has below servers , there could be more servers server1 server2 server3 server4
how can I copy file (file.txt on all servers using scp command) at /tmp/ location .
Assuming bash
:
for server in $(cat server.txt)
do
scp file.txt "$server":/tmp/
done
Parallel mode (don't use this if server.txt is massive as you can run out of bandwidth, stall the connections, and then have a hard time figuring out what succeeded and what failed):
for server in $(cat server.txt)
do
scp file.txt "$server":/tmp/ &
done
wait
As requested, now with password support:
while read SERVER PASSWORD
do
sshpass -p "$PASSWORD" scp file.txt "$SERVER":/tmp/
done <./server.txt
Put, in server.txt
, the first server's hostname, space, the first server's password on the first line and so on.