将文件远程复制到同一目录到所有主机名

Remote copy file to same directory to all hostnames

我正在尝试编写分发脚本以将文件从主机文件复制到指定的主机名并进入同一目录。

例如:

dist -hostname1 file.txt
dist -all file.txt

-all 应该能够分发到网络上的所有主机名。

我知道这可能可以通过 rcp 命令完成

您可以使用 scp 来做到这一点。它使用 ssh 来安全地复制文件。现在 rcp 只是 scp 命令的别名。

用户是远程机器上的登录名。

将文件复制到 /file-dest-dir 中的主机

scp file.txt user@host:/file-dest-dir

一个脚本复制到多个主机:

file=
hosts="host1 host2 host3"
for host in $hosts
do
     scp "" user@${host}:
done

从 /etc/hosts

获取主机
hosts=$(awk '!/^#/ {print }' /etc/hosts)
for host in $hosts
do
     scp "" user@${host}:
done