?
Solved

Script to scp in the background

Posted on 2008-10-16
9
Medium Priority
?
1,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 336 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 332 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 
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 332 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

762 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