Solved

Script to scp in the background

Posted on 2008-10-16
9
1,117 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now