如何ssh到某个目录,然后能够使用FIND命令查找某些文件并对其进行gunzip压缩



大家好,我不去ksh。我要做的是编写一个脚本,将一个(或多个)zip文件从本地目录scp到远程主机。然后将ssh的脚本放入远程主机,对我刚才scp过的文件进行压缩。有什么简单的方法可以做到这一点吗。我一直在尝试,但一旦我用ssh连接到远程主机,我的其余命令就不再像cd/file/目录那样运行,然后是gzip-d/文件等等…

NB:不要混淆"zip"one_answers"gzip"这两种不同的动物

这应该有效:

cd <local_directory>
# collect files names as $1 $2 ... $N
set -- *.gz   # or use your own filter like "dumps*.gz"
# put source file a tar archive  and send it as input to ssh
# then, on the other side, untar the file then decompress
tar cf - $* | ssh <user>@<remote_host> "cd <remote dir> && tar xf - && gunzip $*

注意:如果"cd"因任何原因失败,则使用"&&"而不是";"来防止执行"tar"命令

最新更新