hooblei
hooblei

Reputation: 3240

Send tar output and multiple commands over ssh

I would like to pass the output of a tar command and multiple commands which handle the tar stream over ssh ... something like this

tar -zcf - foo | ssh $host << EOF
tar -xf -
do-something-with-foo
do-other-things
EOF

doesn't work but is this somehow possible?

Upvotes: 0

Views: 184

Answers (1)

user464502
user464502

Reputation: 2383

Wrap everything up in a generated script that you pass to the remote host.

{
        echo 'uudecode -o- <<EOT | tar -xzf-'
        tar -czf- foo | uuencode -m foo
        echo EOT
        echo do-something-with-foo
        echo do-other-things

} | ssh -T $host

The echo output will be run on the remote host, the tar | uuencode runs locally. The purpose of the uuencode is so that we can wrap the output into a heredoc on the remote end, bypassing the need for severe file descriptor juggling.

Upvotes: 1

Related Questions