0

こんにちは、私は ksh ではありません。私がやろうとしているのは、ローカル ディレクトリからリモート ホストに (または多くの) zip ファイルを scp するスクリプトを書いていることです。次に、スクリプトをリモート ホストに ssh して、scp したばかりのファイルを gunzip します。これを行う簡単な方法はありますか。試行を続けますが、リモートホストに ssh 接続すると、残りのコマンドは cd /file/directory のように実行されなくなり、次に gzip -d / filesなど...

4

1 に答える 1

0

注意: 「zip」と「gzip」を混同しないでください。2 つの異なる動物です。

これはうまくいくはずです:

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」コマンドが実行されないようにする

于 2014-01-18T10:15:07.130 に答える