Solved

Script to scp in the background

Posted on 2008-10-16
9
1,120 Views
Last Modified: 2013-12-26
Experts,
Can you provide me a script to scp the files from one server to other in the background. I dont have the flexiblity for creating the equalance between the servers to bypass the password as they are production servers and need a change request.
I tried to write a script by not able to figure out how to pass the password to the script and make it run in the background. There are like 80 files that i need to transfer and a script to automate that would be wonderful.

Please advice or provide me with a template if you have any

Thanks
0
Comment
Question by:blazin_sun
9 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 84 total points
ID: 22734354
You will either need to use expect or a Perl script, which I suspect you'll need a change request for anyway, so if I were you, I would put a change request in to setup ssh keys as this will be your easiest option.
0
 

Author Comment

by:blazin_sun
ID: 22736563
Is there no way to write a script and pass the password and make scp run in the background?
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 83 total points
ID: 22737281
expect is the solution if the script is automated and have to run by e.g. crontab.

But if you want to run it from the command line then give the password then you want it to run in the background then try

use either ksh / bash / csh then

run the script or scp command

type the password
press cntrl-Z
run bg

this will send the job to the background from the command line and you can monitor it with command jobs
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 48

Expert Comment

by:Tintin
ID: 22737359
>Is there no way to write a script and pass the password and make scp run in the background?

No.  You have 2 options

1.  Setup ssh keys
2.  Use a tool like expect or Perl with one of the Expect modules.
0
 
LVL 16

Assisted Solution

by:Bryan Butler
Bryan Butler earned 83 total points
ID: 22754792
Your best bet is probably Expect, and the best thing there is that is allows you to "expect" output....wait for it and then continue.  Whereas otherwise you are just sending keystrokes and hoping you are sending the right thing at the right time.  If you are sure that you can use a "wait/pause" statement because it will always take a max of X amount of time to get a response (so you can send the next "keystrokes"), or that you can just run all the commands, one after another, w/o waiting for a response...or even if you could send the "responses" to a file or capture them....then  you could get around using expect, but you would be basically rolling your own "pseudo" expect, so then why not just use expect.  
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 25291633
I'd also check into powershell CPT3.  I've been finding more and more tools/cmdlets that make things so easy to program.  Here's one link that might help:

http://www.networkworld.com/community/node/22710
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 25850422
Over a year old.   Please close.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question