Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008

    Unanswered: find files on the remote server and scp

    Hello Gurus,
    I need some help with the syntax , i am getting a error "find: missing argument to `-exec'"
    ssh -ql <user> <source:directory> -name "*.pdf" -exec scp '{}'<user>@destination:directory>\;

    thank you in advance.

  2. #2
    Join Date
    Oct 2002
    Baghdad, Iraq
    You're killing me here.

    ssh -ql <user> <source:directory> -name "*.pdf" -exec scp '{}'<user>@destination:directory>\;
    Now, I'm presently sitting at an OS X 10.5 box. I have no idea even what shell you're running, let alone the version of ssh you have.

    My ssh man page says:

    -q is quiet mode

    -l <user> would be the login

    Everything after this looks like it was supposed to be part of a find command! Here's the problem: the -exec option sucks. Use -print0 and xargs -0. (This basically directs find to spit out a null-delimited list of files, and the -0 option to xargs directs it to expect a null-delimited list of files.)

    Further, are you copying a bunch of stuff back to your computer? Rather than making new connections via scp, just send yourself a tarball.

    Assuming you're using some sh derivative (e.g. bash), I'd suggest:

    ssh 'find /source/dir -name "*.pdf" -print0 | xargs -0 tar -cO' | tar -xivf - -C /destination/dir
    For tar: the -i option is uncommon, but basically xargs will call tar repeatedly and the data streams will be jammed together. Each time tar is done, it will leave an "I'm done!" marker, which would normally tell the decoding tar to stop. The -i option tells it to ignore this and keep reading.

    This sounds flaky, I know, but it's very similar to the situation you had with magnetic tapes, which is what tar was specifically designed for.

    For xargs: you can control how many times tar is called with the -n option for xargs. The default is every 5000 files, which should be fine.

    If you need to connect to a third computer, you can still use scp:

    ssh 'find /source/dir -name "*.pdf" -print0 | xargs -0 -J % scp %'
    The -J % option tells xargs to put the list of files in where it sees %.
    Last edited by sco08y; 04-26-08 at 23:41.

  3. #3
    Join Date
    Oct 2002
    Baghdad, Iraq
    In the other thread you were asking about repeated requests for authentication.

    The best way to avoid all that crap is like so:

    Run ssh-keygen on one host. To avoid any passwords at all, enter a blank passphrase, at your own risk, of course.

    You'll see something like this:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/ben/.ssh/id_rsa): 
    Created directory '/Users/ben/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /Users/ben/.ssh/id_rsa.
    Your public key has been saved in /Users/ben/.ssh/
    The key fingerprint is:
    22:d9:de:f4:a7:2b:3c:55:71:98:65:7f:fa:c9:34:0b ben@stogie.local
    Do this on all your accounts on all your hosts that you want ssh access to and from.

    Now, that file is your public key. Mine looks like this:

    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlPP0T41N5W+kIp+MbekXyPwMy5f/lTfLAs1S93+EEeYigdwZFKWk937jzPrU1Uuwu+4E2rnw0EwqsM0nk2Fvdav1grbga06IgILHdD6lYZR/RT00ekqdn2ZhqgMcEryFkb7aEGUw1uxEI2O4R+axFErY3VTZjRgHfp03ok9rzomLV0YoeU1TlydeKYqWIHSVnjR3Flib43BTwZGeym2PQhWHcShCKdHy8OgfVBAdVUmywc0m/2IzF684ZZjNjd2aiaFC8fWRtrC24OWBqeRGgtvAU2ct/RtNmAopNqzKOufOaxe7hq2yXQVGJoL1xACYGS+i/ttIv1RbtlCZoDgfdw== ben@stogie.local
    Each public key is one long line. Copy all these files into one big list of public keys, called authorized_keys. On mine it is "/Users/ben/.ssh/authorized_keys". Copy that file to each computer.

    Viola. You shouldn't need to enter any passwords whatsoever.

    WARNING: by doing this, you're giving all these accounts complete control over each other.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts