scpHow to SCP to multiple hosts?
SCP (Secure Copy Protocol) is a secure way to transfer files between two hosts. To SCP to multiple hosts, you can use a bash script with a for loop.
#!/bin/bash
for host in host1 host2 host3
do
scp file.txt user@$host:/home/user/
done
This will copy the file.txt to the /home/user/ directory of each host.
Parts of the code:
#!/bin/bash
- This is the shebang line which tells the system which interpreter to use.for host in host1 host2 host3
- This is the for loop which will iterate over the list of hosts.scp file.txt user@$host:/home/user/
- This is the scp command which will copy the file.txt to the /home/user/ directory of each host.
Helpful links
More of Scp
- Running SCP in quiet mode
- Is it possible to SCP files in parallel?
- How to show progress when using SCP?
- How to overwrite files using SCP?
- How to transfer files using wildcards with SCP?
- How to use an SSH key when using SCP?
- How to automatically create destination directory when using SCP?
- How to run SCP in verbose mode?
- How to use a different port when using SCP?
- How to use SCP with a password?
See more codes...