From: Mark Muskardin Date: 2008-02-08T07:46:08+09:00 Subject: Re: using net::ssh shell to sudo to another user and execute commands unsubscribe On 2/7/08 5:44 PM, "Rha" 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" > 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 >