linux - 在服务器上运行的 Bash 脚本,访问本地文件

标签 linux bash

<分区>

我在服务器上运行一个脚本,该脚本应该将所有文件从源目录复制 x 次到目标目录。当两个目录都在服务器上时,它运行良好。

如何从本地目录(如 C:\dir)复制到服务器目录?

最佳答案

如果您在系统之间具有 SSH 访问权限,则可以将本地目录推送到远程位置,如下所示:

printf -v ssh_cmd 'mkdir -p %q && tar -C %q -x' \
  "$dest_directory" "$dest_directory"
tar -C "$source_directory" -c . | ssh other_host "$ssh_cmd"

...或者类似地将远程目录拉到本地目录:

printf -v ssh_cmd 'tar -C %q -c .' \
  "$source_directory" "$source_directory"
mkdir -p "$dest_directory"
ssh other_host "$ssh_cmd" | tar -C "$dest_directory" -x

关于linux - 在服务器上运行的 Bash 脚本,访问本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935892/

相关文章:

linux - 在 shell 脚本中更正 if ..elif 中的输出

bash - 引用命令替换的正确方法

bash - 为什么带有不带引号的变量的 glob 会扩展到所有文件?

linux - 在 elasticsearch_exporter 容器上安装 python3 python3-pip 和 awscli

linux - 如何在Linux中显示所有文件(包括隐藏文件)的列表?

linux - 不会立即处理通过管道传输到 awk 的输出

linux - 如何从 lsof 获取文件名?

bash - 为什么在 bash 中比较数字时 "[[ 10 < 2 ]]"为真?

linux - Unix/Linux 和 MQ 脚本解释

c++ - 一个用户崩溃时共享内存中的互斥锁?