使用scp将多个文件发送到多个位置

Abh*_* py 5 linux

我需要将多个文件发送到多个位置,但找不到合适的方法.

例如,我需要将file1发送到location1,将file2发送到location2.这就是我在做的事情:

scp file1 file2 root@192.168.1.114:/location1 /location2
Run Code Online (Sandbox Code Playgroud)

但这不起作用.有什么建议吗?

Ala*_*ith 8

使用单个scp命令无法发送到多个远程位置.它可以容纳多个源文件,但只能容纳一个目标.只使用scp命令本身,它必须运行两次.

scp file1 file2 user@192.168.1.114:/location1 
scp file1 file2 user@192.168.1.114:/location2
Run Code Online (Sandbox Code Playgroud)

可以通过运行for循环将其转换为"单行".以bash为例:

for REMOTE in "user@192.168.1.114:/location1" "user@192.168.1.114:/location2"; do scp file1 file2 $REMOTE; done
Run Code Online (Sandbox Code Playgroud)

scp仍然运行多次,但循环负责迭代.也就是说,我发现运行命令一次更容易,点击向上箭头(在大多数环境中恢复原始命令),只需更改远程位置并重新发送即可.