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
- How to run SCP in verbose mode?
- Running SCP in quiet mode
- How to show progress when using SCP?
- How to overwrite files using SCP?
- How to transfer files recursively using SCP?
- Is it possible to SCP files in parallel?
- How to use SCP with a password?
- How to list files using SCP?
- How to enable logging when using SCP?
- How to SCP from a remote to a local machine?
See more codes...