Executing interactive system commands

Hello.

I need to execute SCP (secure copy) command from Ruby script on Windows.
The problem is that this command needs a password to be typed and
supports no switch or option to provide the password.

Is there any way to catch the command’s output and give it the passwod?

P.S. Sorry for my bad English.

···

Vitaly Semkin
Network Security Administrator
Sibirtelecom
+7 3832 270669

Vitaly Semkin wrote:

Hello.

I need to execute SCP (secure copy) command from Ruby script on Windows.
The problem is that this command needs a password to be typed and
supports no switch or option to provide the password.

Is there any way to catch the command’s output and give it the passwod?

I mean, it goes like this:

scp2 ./file1 user@host:file1
user@host’s password:_

And there’s no way to provide the password as a command line argument.
But I need to call this command out of a Ruby script, thus, I need to
catch the command’s output and give it the password.

Help!

···

Vitaly Semkin
Network Security Administrator
Sibirtelecom
+7 3832 270669

A better solution would be to use a public/private key to do
passwordless authentication. This may not fit in your environment, but
using a passwordless key would solve your problem.

···

On Sun, 2003-02-09 at 02:38, Vitaly Semkin wrote:

Hello.

I need to execute SCP (secure copy) command from Ruby script on Windows.
The problem is that this command needs a password to be typed and
supports no switch or option to provide the password.

Is there any way to catch the command’s output and give it the passwod?

P.S. Sorry for my bad English.

Scott Brooks scottbrooks@telusplanet.net

Hi,

scp2 ./file1 user@host:file1
user@host’s password:_

You may want to detach CTTY?

untested code

popen(“-”, “r+”) do |f|
if f
f.gets(“password:”)
f.puts(password)
else
Process.setsid
exec(“scp2”, file, host)
end
end

And there’s no way to provide the password as a command line
argument. But I need to call this command out of a Ruby script, thus,
I need to catch the command’s output and give it the password.

It’s insecure to pass a password as a command line.

···

At Mon, 10 Feb 2003 11:15:43 +0900, Vitaly Semkin wrote:


Nobu Nakada

Expect is made to do what you want. There is a Windows version,
although I’ve never used it. See the following website:

http://expect.nist.gov/

There is something similar built into Ruby, expect.rb, which is in the
standard library for 1.6.8. I have not used it, but it may do what you
want. It is also short enough to reproduce here:

$expect_verbose = false

class IO
def expect(pat,timeout=9999999)
buf = ‘’
case pat
when String
e_pat = Regexp.new(Regexp.quote(pat))
when Regexp
e_pat = pat
end
while true
if IO.select([self],nil,nil,timeout).nil? then
result = nil
break
end
c = getc.chr
buf << c
if $expect_verbose
STDOUT.print c
STDOUT.flush
end
if mat=e_pat.match(buf) then
result = [buf,*mat.to_a[1…-1]]
break
end
end
if iterator? then
yield result
else
return result
end
nil
end
end

···

On Sunday, February 9, 2003, at 09:15 PM, Vitaly Semkin wrote:

Vitaly Semkin wrote:

Hello.
I need to execute SCP (secure copy) command from Ruby script on
Windows.
The problem is that this command needs a password to be typed and
supports no switch or option to provide the password.
Is there any way to catch the command’s output and give it the
passwod?
[snip]