Ssh – How to extract archive via network

solarisssh

I have two Solaris servers. On server1 I have a file, archive.tar.gz. I need to extract it using ssh to server2.

So, I write the commands:

ssh server2 < archive.tar.gz | gunzip -c | tar -xf - -C /home/

But I got an error:

Pseudo-terminal will not be allocated because stdin is not a terminal.

How to copy the file correctly?

Best Answer

I believe you could do something like this:

$ cat archive.tar.gz | ssh server2 "tar zxvf -"

If you need to control the directory where it gets extracted to on server2:

$ cat archive.tar.gz | ssh server2 "cd /path/to/dir; tar zxvf -"

Solaris

Given you're on Solaris your version of tar is likely to not include any of the compression features that GNU tar offers. Fear not you can still do this command, we just need to decompose the cat archive.tar.gz into a command that can first uncompress the tarball.

Something like this should do:

$ cat archive.tar.gz | ssh server2 "(cd /some/dir; gunzip | tar xf -)"

Or this:

$ gzip -dc < sample.tar.gz | ssh server2 "cd /path/to/dir; tar xvf -"

Or this:

$ gunzip sample.tar.gz | ssh server2 " cd /path/to/dir; tar xvf -"
Related Question