Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to have environment variables on a remote host evaluated when using SCP?

For instance, let's say I have $FOO= /mydir on host A; how would I do something like:

scp dogbert@hostA:$FOO/evil-secret-plans.txt .

Of course, $FOO isn't defined on my local machine so the above command doesn't work as it is.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Try it like this:

scp dogbert@hostA:$(ssh dagobert@hostA "echo $FOO")/evil-secret-plans.txt .

A bit of overhead.

share|improve this answer
add comment

The easier thing to do is to send the file with tar or gzip through stdout / stdin.

tar -czf - ./evilsecretfile.txt | ssh user@remoteHost "cd \${varOnRemoteSystem} ; tar -xzf - ."

or

gzip -c localFileName.txt | ssh user@remoteHost "gzip -d > /remote/path/\${varOnRemoteSystem} ; chmod 666 /remote/path\${varOnRemoteSystem}"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.