How can I unlock multiple tar files on top of ssh?

I am trying to unpack several tar files on top of ssh:

ssh user@hostname "cat /dir/file*.tgz" | tar xvzf -

The above only works in the first file match on the remote server. The local (dest) server receives only one file. Wildcard checked for matching multiple files.

Is there any other way to do this?

+5
source share
5 answers

(Change after the first attempt failed :)

Another idea, avoiding multiple calls ssh, as well scp(since each file requires at least one switch):

ssh user@hostname 'tar cf - /dir/file*.tgz' | tar xf - --to-command='tar xzvf -'

tar , , tar , , tar xzv . base64- sehe, , .

+4
mkdir /tmp/tars
scp 'user@hostname:/dir/file*.tgz' /tmp/tars/
foreach tarname in /tmp/tars/*.tgz; do tar xzvf "$tarname"; done

:

ssh user@hostname 'ls /dir/file*.tgz' | while read tarname; 
do
    ssh user@hostname "cat '/dir/$tarname'" | tar xzvf -
done
+2

find, exec .

ssh user@hostname 'find /path/to/dir -name "*.tar.gz" -exec tar xvf "{}" ";"'

ssh, bash script.

+1

CarpeNoctem , ssh .

(online ):

 (echo '#!/bin/sh'; 
  for a in /dir/file*.tgz
  do 
      echo 'base64 -d <<"TARIMAGE" | tar xvzf -'
      base64 "$a"
      echo "TARIMAGE"
  done) | ssh -C remote 'cd /targetdir && sh -'

, , script script:

gen_script.sh, chmod + x

#!/bin/bash
echo '#!/bin/sh'; 
for a in /dir/file*.tgz
do 
    echo 'base64 -d <<"TARIMAGE" | tar xvzf -'
    base64 "$a"
    echo "TARIMAGE"
done

scp gen_script.sh user@hostname:
ssh -C user@hostname /home/user/gen_script.sh | (cd targetdir && sh -)

, :

  • uuencode, od, xxd, pgp whatnot base64
  • ssh (ssh-C) .
  • / , ; , :)
0

, . ssh tar SSHFS,

mkdir hostname-dir.tmp
sshfs user@hostname:/dir hostname-dir.tmp
for a in hostname-dir.tmp/*.tgz; do tar xvf "$a"; done
fusermount -u hostname-dir.tmp

AVFS ยน. , FUSE, .

mountavfs
mkdir hostname-dir.tmp
sshfs user@hostname:/dir hostname-dir.tmp
for a in ~/.avfs$PWD/hostname-dir.tmp/*.tgz; do cp -Rp "$a#"/* .; done
fusermount -u hostname-dir.tmp

zsh, for glob.

cp -Rp ~/.avfs$PWD/hostname-dir.tmp/*.tgz(e\''reply=($REPLY\#/*)'\') .

ยน AVFS SSH, , : AVFS . SSHFS - . >

0

All Articles