LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2009, 04:01 PM   #1
AlexDBA
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 0
how do i pass a password to scp prior to running it in the background? keys disabled


I have a script that runs a bunch of SCPs in the background. I need to somehow pass the password to SCP before it starts running in the background. The SSH keys are disabled in most environments, so that's not an option. SSH has an -f option "Requests ssh to go to background just before command execution", but I don't see anything similar for scp. Any help or insight would be appreciated.

Thanks
 
Old 04-30-2009, 04:30 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by AlexDBA View Post
I have a script that runs a bunch of SCPs in the background. I need to somehow pass the password to SCP before it starts running in the background. The SSH keys are disabled in most environments, so that's not an option. SSH has an -f option "Requests ssh to go to background just before command execution", but I don't see anything similar for scp. Any help or insight would be appreciated.

Thanks
Basically you'd have to write a simple expect script.
 
Old 04-30-2009, 04:46 PM   #3
AlexDBA
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
Basically you'd have to write a simple expect script.
Thanks for the info but if Expect was something already packaged with linux, it would have been an option. It wouldn't be a good idea to install something throughout our environment for one simple use. There has to be a way of achieving this.

Last edited by AlexDBA; 04-30-2009 at 04:48 PM.
 
Old 04-30-2009, 05:14 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by AlexDBA View Post
The SSH keys are disabled in most environments, so that's not an option.
Why do you say that?

Anyways, the scp program lacks the option but you can get the desired effect with connection multiplexing:
Code:
# setup the connection
ssh -fNM -o "ControlPath $HOME/%r@%h:%p.ssh" host
...
# transfer the file in background
scp -o "ControlPath $HOME/%r@%h:%p.ssh" file host:file &
SCP_PROC=$!
...
# close the connection after transfer ends
wait $SCP_PROC
ssh -o "ControlPath $HOME/%r@%h:%p.ssh" -O exit host
 
Old 05-01-2009, 12:05 PM   #5
AlexDBA
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ntubski View Post
Why do you say that?

Anyways, the scp program lacks the option but you can get the desired effect with connection multiplexing:
Code:
# setup the connection
ssh -fNM -o "ControlPath $HOME/%r@%h:%p.ssh" host
...
# transfer the file in background
scp -o "ControlPath $HOME/%r@%h:%p.ssh" file host:file &
SCP_PROC=$!
...
# close the connection after transfer ends
wait $SCP_PROC
ssh -o "ControlPath $HOME/%r@%h:%p.ssh" -O exit host

Thanks, It will work for me but I can't close the connection without killing the process and removing $HOME/%r@%h:%p.ssh. -O is not an available option.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp needs three times password in wrong password case!!! JATA01 Programming 6 12-01-2008 05:28 AM
Make SCP run in background? Moonman Linux - Software 3 11-29-2007 07:46 AM
scp, how to pass password in script ebel.velda Linux - Software 4 07-17-2007 05:13 PM
SCP as a background process Edmunds Linux - General 4 12-31-2006 12:20 PM
Pass SCP User passward in shell program michaelyu33 Programming 3 03-18-2005 12:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration