find -exec scp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find -exec scp
# 1  
Old 07-08-2009
[SOLVED]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:

Code:
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.

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

What's wrong ?

Last edited by Tex-Twil; 07-09-2009 at 04:50 AM..
# 2  
Old 07-08-2009
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.

Last edited by zaxxon; 07-08-2009 at 10:24 AM.. Reason: Added info
# 3  
Old 07-08-2009
Quote:
Originally Posted by zaxxon
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:

Code:
~$ 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:

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

# 4  
Old 07-08-2009
Taking a hint from the man page of find on Linux:
Code:
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
Code:
$ find test -type f  -exec scp ${SCP_OPTS} -r {} root@192.168.0.1:/root/. \;

# 5  
Old 07-08-2009
As suggested try it with xargs:

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

[ Assuming you have set a passwordless login. ]


Quote:
Originally Posted by Tex-Twil
All the files are copied but the destination is the "{}" file on the remote host:

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

... find's -exec does not support that kind of replacement.
# 6  
Old 07-08-2009
ok so this confirm my problem.

Thanks,
Tex

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

Quote:
Originally Posted by pludi
Taking a hint from the man page of find on Linux:
Code:
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.

I'm not sure to get the meaning of that Smilie

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 ----------

Quote:
Originally Posted by rubin
As suggested try it with xargs:
Code:
find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:/full/path/to/dir/

What about
Quote:
find test -type f | xargs -i scp '{}' root@192.168.0.1:'{}'
This would avoid using the full path on the target host.

Last edited by Tex-Twil; 07-08-2009 at 11:29 AM..
# 7  
Old 07-08-2009
Quote:
Originally Posted by Tex-Twil
ok so this confirm my problem.

Thanks,
Tex
So was your problem solved ?



Quote:
Originally Posted by Tex-Twil
What about

Quote:
find test -type f | xargs -i scp '{}' root@192.168.0.1:'{}'
This would avoid using the full path on the target host.

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:

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

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

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


Last edited by rubin; 07-08-2009 at 12:16 PM.. Reason: added final option
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Chaining together exec within find

I need to do the following with a find command on my AIX box Find all files that are -type f Then do the following steps:- Take a listing of them, and write them to a log in /directory/backup/log Tar them up in /directory/backup/tar and remove the files. Here is what I have... (22 Replies)
Discussion started by: jeffs42885
22 Replies

2. Shell Programming and Scripting

2 exec in find

Guys, I want to find the log files greather than 23 days and i want to perform 2 things here. one is to list the files and second is to gzip the files. hope this can be done using sh -c option. but not sure the exact command. find . -name "*.log" -mtime +23 -exec ls -la {} \; ... (5 Replies)
Discussion started by: AraR87
5 Replies

3. Shell Programming and Scripting

what's wrong with my -exec in find

find ./ -name *Kconfig -exec cat {} \; but it won't work with find ./ -name *Kconfig -exec cat {} |grep CONFIG_MTD |grep depend \; how could I handle this (14 Replies)
Discussion started by: yanglei_fage
14 Replies

4. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

5. Ubuntu

Find and EXEC

This is a huge issue. and I need it fixed ASAP. account-system gate-system race_traffic_sensor achievement-system global race_voicepack admin glue-system realdriveby admin-system gps realism-system... (5 Replies)
Discussion started by: austech360
5 Replies

6. Ubuntu

Find and exec

Hello, I am a linux newbe. I want to install a program. I can download it only with wget command from internet. As far as i know this wget command does not transfer the exacutable flags. Because of that i wanted to find all configure files and change their mod to 744. I found this... (1 Reply)
Discussion started by: disconnectus
1 Replies

7. UNIX for Dummies Questions & Answers

Find Exec

Hello All, Is there a way to make exec do a couple of operations on a single input from find? For example, find . -type d -exec ls -l "{}" ";" I would like to give the result of each "ls -l" in the above to a wc. Is that possible? I want to ls -l | wc -l inside... (1 Reply)
Discussion started by: prasanna1157
1 Replies

8. Shell Programming and Scripting

Using MV FIND and -EXEC

Hi, i would like to rename files in directories and subdirs. Files contains specific french or strange caracters. I want to replace all non alpha-numerics by _ (underscore) First, i made this, but i think the "for" is limited. How can i do this directly by FIND ? for file in $(find .... (0 Replies)
Discussion started by: degraff63
0 Replies

9. Shell Programming and Scripting

| with find -exec

can we use |(pipe operator) with find -exec.....? or can pipe the output of find command to another command...? if not, why...? pls explain (3 Replies)
Discussion started by: vijay_0209
3 Replies

10. UNIX for Advanced & Expert Users

find and exec

Hi, Happy new year. Would you be so kind to explain me what does this instruction : find /rep/app -type l -exec ls -l {} \;> allink.lst Many thanks. (2 Replies)
Discussion started by: big123456
2 Replies
Login or Register to Ask a Question