find -exec scp

Hello,
I'm facing a problem with a command that works on Linux but not on Unix (Solaris 10).

I want to find files and scp then to another server. This command is:

find /path -type f -exec scp  {} root@node000C76211737:{} \; 

All the files are found correctly but it looks like the last "{}" is not replaces by the file name and all the files are actually copied to file {} in the root's home dir.

$ ll
-rw-r--r--   1 root     root           0 Jul  8 14:38 {}

What's wrong ?

Hm works even on AIX and it's find will be more limited than GNU's find or on Solaris I bet. Maybe try a workaround with xargs?

Edit: I jsut noticed that scp told me it transfered the files but I can't find them by no means. Maybe I would need a workaround in that case on AIX too. Just as info that my 1st message is not correct it seems.

Yeah everything looks fine:

~$ find test -type f  -exec scp ${SCP_OPTS} -r {} root@192.168.0.1:{} \;
3.txt                100% |***********************************************************|     0       00:00
4.txt                100% |***********************************************************|     0       00:00
5.txt                100% |***********************************************************|     0       00:00
2.txt                100% |***********************************************************|     0       00:00
1.txt                100% |***********************************************************|    12       00:00

All the files are copied but the destination is the "{}" file on the remote host:

$ file /root/\{\}
/root/{}:       ascii text

Taking a hint from the man page of find on Linux:

The string `{}' is replaced by the current file name being
processed everywhere it occurs in the arguments to the command, not just in
arguments where it is alone, as in some versions of find.

Might be that that's your problem. Try running it as

$ find test -type f  -exec scp ${SCP_OPTS} -r {} root@192.168.0.1:/root/. \;

As suggested try it with xargs:

find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:/full/path/to/dir/

[ Assuming you have set a passwordless login. ]

... find's -exec does not support that kind of replacement.

ok so this confirm my problem.

Thanks,
Tex

---------- Post updated at 09:01 AM ---------- Previous update was at 08:57 AM ----------

I'm not sure to get the meaning of that :slight_smile:

Does the "alone" means that {} has to be surrounded by spaces in order to be replaced ?

---------- Post updated at 09:12 AM ---------- Previous update was at 09:01 AM ----------

What about

This would avoid using the full path on the target host.

So was your problem solved ?

Well..., try it and see what happens - it'll default to the home directory, but I prefer to put a path in front of the filenames, so you can do something like this:

find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:~/'{}'

____
Even this will be enough ( defaulting to remote server's home dir ) ...

find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:

Hi

find test -type f  | xargs -i scp  '{}' root@192.168.0.1:'{}'
find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:~/'{}'

There is a difference between those two commands. The 1st just use the full path of the found file and copies it to the same path.
/etc/myapp/test.txt --> /etc/myapp/test.txt

The second will copy the full path to the home dir.
/etc/myapp/test.txt --> ~/etc/myapp/test.txt

Thanks for your help. Problem sovled