简体   繁体   English

根据文件名条件复制文件

[英]Copying files based on filename condition

Copy all files from remote only if filename consists of any name in my file.txt file. 仅当filename由我的file.txt文件中的任何名称组成时,才从远程复制所有文件。

file.txt contains names like file.txt包含类似

rahul
jon
babra

Currently I am doing this: 目前,我正在这样做:

while read p; do      
scp -i somefile.pem myuser@myip:myfolder/\*$p\* .
done<file.txt

But this would open connection to remote for every name in my file.txt. 但这将为我的file.txt中的每个名称打开到远程的连接。

I am looking for an optimization to serve all files in a single connection ? 我正在寻找一种优化方法来在单个连接中提供所有文件?

Open a master connection that each subsequent scp can reuse. 打开一个主连接,每个后续的scp均可重用。 See the various Control* options in man ssh_config for advice on using a more secure control path. 有关使用更安全的控制路径的建议,请参见man ssh_config的各种Control*选项。

# Don't run a command (-N), but open a reusable connection (-M and -S)
# then go to the background (-f)
ssh -fNM myuser@myip -S "%C"

while read p; do
  # Reuse the open connection (-S)
  scp -i somefile.pem -S "%C" myuser@myip:myfolder/\*$p\* .
done < file.txt

# Close the background connection
ssh -S "%C" -O exit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM