[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: using net::ssh shell to sudo to another user and execute commands

Mark Muskardin

2/7/2008 10:46:00 PM

unsubscribe


On 2/7/08 5:44 PM, "Rha" <rha7_@hotmail.com> wrote:

> Just tested this mini-script on Windows, and it works.
>
> require 'net/ssh'
>
> Net::SSH.start('yourhost.com', :port => 22, :username => 'youruser',
> :password => 'yourpassword') do |session|
> shell = session.shell.sync
> puts "connected"
> puts "ls"
> shell.send_command "echo 'yourpassword' | sudo -S ls"
> puts 'Exiting'
> shell.exit
> puts "Exited"
> end
>
> Hope this works for you, btw, I couldn't make it work by sending the
> text as parameter to send_command :(, at least you can make it work
> some way.
>
> Gabriel Medina.
>
>
>
> On Thu, 7 Feb 2008 06:22:19 -0800 (PST), "wbsurfver@yahoo.com"
> <wbsurfver@gmail.com> wrote:
>
>>
>> The following program does not get past the part where sudo asks for a
>> password. Any ideas ?
>> This is run from windows onto a linux box, so I can't use a local ssh
>> command.
>>
>> it outputs
>>
>> connected
>> cd
>>
>>
>>
>> Net::SSH.start(host, :port => 22, :username => usr, :password => pwd)
>> do |session|
>>
>> shell = session.shell.sync
>>
>> puts "connected"
>>
>> shell.cd '/somedir'
>>
>> puts "cd"
>>
>> shell.send_command 'sudo su otheruser', pwd
>>
>> puts 'sudo'
>>
>> shell.cp 'file_6.js tt6.js'
>>
>> puts "cp"
>>
>> shell.exit
>>
>> puts "exit"
>>
>> end
>