Solved

Script to scp in the background

Posted on 2008-10-16
9
1,127 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 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

724 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