Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, Would like to know how I will create a script that will let me run multiple scp commands? That will copy files one at a time from 8 servers. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Location
    Manila
    Posts
    17

    Question Script for Multiple Runs


    Hi,

    Would like to know how I will create a script that will let me run multiple scp commands? That will copy files one at a time from 8 servers.

    I already figured out the complete scp syntax, I just don't know how to make them run in sequence...

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Just put them all one after the other in a script. Or separate them with a semi-colon, but new lines are easier to read. put the command line interpreter at the top of the script (e.g., /bin/bash), and make sure the script is executable. that's about it. here's an example script, called scp-script.sh:
    Code:
    #!/bin/bash
    
    scp file1.txt remotepc1:/tmp
    scp file1.txt remotepc2:/tmp
    scp file1.txt remotepc3:/tmp
    #etc
    Of course, you can use a bash loop to make the script less repetitive.

    now to make it executable:
    Code:
    chmod +x scp-script.sh
    and then to run it;
    Code:
    ./scp-script.sh

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,512
    He probably wants to avoid inputting the password every time... Create a public/private keypair, install the public part on the servers in question, install the private part (the .pem file) on the client in ~/.ssh, configure the servers sshd to allow passwordless (but key authenticated) logins, and then use the -i path-to-pem-file option for ssh. You use the ssh-keygen program to generate your keys.

    FWIW, that's what we do to allow access to our cloud-based servers. Only authorized people get a copy of the appropriate keys and security gets really cranky when they have to change and redistribute them because someone had a brain-fart!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Feb 2013
    Location
    Manila
    Posts
    17

    Red face

    Quote Originally Posted by Rubberman View Post
    He probably wants to avoid inputting the password every time... Create a public/private keypair, install the public part on the servers in question, install the private part (the .pem file) on the client in ~/.ssh, configure the servers sshd to allow passwordless (but key authenticated) logins, and then use the -i path-to-pem-file option for ssh. You use the ssh-keygen program to generate your keys.

    FWIW, that's what we do to allow access to our cloud-based servers. Only authorized people get a copy of the appropriate keys and security gets really cranky when they have to change and redistribute them because someone had a brain-fart!
    Hi Rubberman, thanks for the info about the -i. I have already created the private and public keys for both my test servers.

  5. #5
    Just Joined!
    Join Date
    Jan 2013
    Posts
    47
    Just create a for loop.

    Code:
    #!/bin/bash
    
    count=10
    for (( i = 1; i < $count; i++ )); do
      # put code here
      scp file[$i].txt remotepc[$i]:/tmp
    done
    And make the the script executable
    Last edited by jgezau; 02-06-2013 at 07:17 PM.

Posting Permissions

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