Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have encountered a small issue with SCP (and also rsync). I need to copy certain files from server A (running SunOS 5.8) to server B (running SunOS 5.10).

First, I get the list of files (several hundred) via ssh and find

FILES=`ssh user@remote find ./ -name "*.sh" -o -name "*.cbs" -print`
scp -r user@remote:"$FILES" /u01/appl/somedir/ 

My problem is, I want to copy files with relative paths, e.g. product/11/ora/clean.sh creating also the directory structure (in result having /u01/appl/somedir/product/11/ora/clean.sh). Currently I am only able to download the file and no directories are created. As you can see I used -r flag in scp.

share|improve this question
    
Unsure of the goal due to the wording but my sense of what you're trying to do is copy a directory tree on the local system to a remote system over ssh but the parent directory paths may be different? Is this something rsync over ssh could help with? –  Joel Davis Apr 2 '13 at 16:44
add comment

1 Answer

The shell will expand your construct user@remote:"$FILES" into something you don't want. The first will have the user@remote: prefix but the rest won't.

You can pipe tar over SSH, so it might be easier to build up an include file with your "find" command as above, then you can do approx this:

find ...stuff... > myfiles
scp myfiles user@remote
ssh user@remote "tar -Imyfiles -cvf - " | tar -C /u01/appl/somedir -xf-

You could probably get crafty and combine the find and the tar with the right quoting.

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.