Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 计数ssh查找结果_Bash_Ssh_Scp_Wc - Fatal编程技术网

Bash 计数ssh查找结果

Bash 计数ssh查找结果,bash,ssh,scp,wc,Bash,Ssh,Scp,Wc,我的脚本中有这一部分,我会将1小时前的文件从一台服务器复制到当前登录的服务器: ssh testuser@sampleServer find /home/testuser/files -type f -mmin -60 > /home/user/bin/tmp/results.txt while read LINE do scp -r testuser@sampleServer:$LINE /home/user/bin/tmp done < /home/user/bin/t

我的脚本中有这一部分,我会将1小时前的文件从一台服务器复制到当前登录的服务器:

ssh testuser@sampleServer find /home/testuser/files -type f -mmin -60 > /home/user/bin/tmp/results.txt

while read LINE
do
    scp -r testuser@sampleServer:$LINE /home/user/bin/tmp
done < /home/user/bin/tmp/results.txt
但我相信这仍然可以改进,因为它是多余的。 你对我如何修改它有什么建议吗?感谢

打开n+1 TCP连接,并为每个复制n个文件执行SSH握手等操作,似乎效率极低

您通常会这样做(同时避免使用那个讨厌的临时文件):

这是假设在任何文件名中没有换行符(这也会破坏您的原始脚本),并且如果远程站点上有镜像目录结构,您不介意在
/home/user/bin/tmp
中创建镜像目录结构

现在,将行计数添加到原始脚本很简单——为什么不在临时文件上运行它呢但在这里也同样容易。只需将
-v
选项添加到提取
tar
过滤器中,并计算输出行数

... | tar -C /home/user/bin/tmp -z -x -v -f - | wc -l

非常抱歉,先生,但我不太清楚。我还是个新手,希望你能理解。我们在远程
ssh
会话中对标准输出创建
tar
存档,并在管道的另一端从中提取文件。这将通过一个SSH会话完成整个事务=$(wc-l Ahh@tripleee我现在明白了。非常感谢!ssh命令将在
/home/testuser
中运行,因此您可以简单地执行
cd文件和查找。
…以避免打印完整的目录路径(从而在目标位置获得树结构的副本)。
ssh testuser@sampleServer '
    find /home/testuser/files -type f -mmin -60 -print0 |
    xargs -r0 tar zcf -' |
tar -C /home/user/bin/tmp -z -x -f -
... | tar -C /home/user/bin/tmp -z -x -v -f - | wc -l