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.
- 02-04-2013 #1Just Joined!
- Join Date
- Feb 2013
- Location
- Manila
- Posts
- 17
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...
- 02-05-2013 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
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:
Of course, you can use a bash loop to make the script less repetitive.Code:#!/bin/bash scp file1.txt remotepc1:/tmp scp file1.txt remotepc2:/tmp scp file1.txt remotepc3:/tmp #etc
now to make it executable:
and then to run it;Code:chmod +x scp-script.sh
Code:./scp-script.sh
- 02-05-2013 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,143
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!
- 02-05-2013 #4Just Joined!
- Join Date
- Feb 2013
- Location
- Manila
- Posts
- 17
- 02-06-2013 #5Just Joined!
- Join Date
- Jan 2013
- Posts
- 33
Just create a for loop.
And make the the script executableCode:#!/bin/bash count=10 for (( i = 1; i < $count; i++ )); do # put code here scp file[$i].txt remotepc[$i]:/tmp done
Last edited by jgezau; 02-06-2013 at 07:17 PM.


Reply With Quote

