views:

288

answers:

4

I need to use scp update some directory at another server. It is similar to

for i in /usr/some/???/unknown/dir
do
cp /usr/some/file $i
done

so how can i do the search while the destination directories are on other server?

thank you

A: 

If you have shell access on the remote server, create a list of the directories remotely (using find, or ls, or whatever you'd use in your shell script), and copy it back to the system you're copying from. Then you can use

for d in file_of_remote_dirs; do
    scp /usr/some/file remote_machine:d;
done
Michiel Buddingh'
+2  A: 
for i in `ssh user@otherhost ls /usr/some/dir/` 
do
 scp user@otherhost:/usr/some/dir/$i .
done
nos
+1  A: 
for i in `ssh user@otherhost find /usr/some -type d -name dir`
do
  scp user@otherhost:/usr/some/dir/$i .
done

the find is what you're looking for I guess...

LB
+4  A: 

Everybody forgets to handle spaces in file names :P

To reuse LB's example:

OLD_IFS=$IFS
IFS=$\'n'
for i in `ssh user@otherhost find /usr/some -type d -name dir`
do
  scp user@otherhost:"/usr/some/dir/$i" .
done
IFS=$OLD_IFS

This will loop over each line of output instead of each word (and $i is quoted).

Eugene
yep you're right... I always forget... but i always say spaces in file names are evil... :-)
LB