From: Eric Hodel Date: 2007-08-19T05:39:56+09:00 Subject: Re: need help. want to use Net::sh to do sudo command On Aug 18, 2007, at 02:35, wbsurfver@yahoo.com wrote: > > I want to do a sudo command to change permissions on our server > because our admin has some kind of build > that blows away the image directory and it ends up having the wrong > permissions after the build. > When the sudo command is run it will prompt for a password and I need > to write the password to it. If I just write to the stream before it > prompts, I'm not sure if it will work ? Also if someone could give me > the exact stuff that they think will work, that would be helpfull as I > am concerned if I play with it and have failed attempts it might lock > my account. I want to be able to email the group and say, 'hey here is > a script that runs every 10 minutes from my pc and fixes the build > problem", If possible, I don't want the admins to be upset with me for > getting my account locked because I was playing around. Our server > runs linux, thanks. Below is sort of what my script would do, but the > password part is missing. As I said, it may be an easy thing, I'm just > affraid of getting it wrong ... > > ---------------------------------------------------------------------- > - > require 'net/ssh' > > host = 'myhost.frog.surf.com' > > > Net::SSH.start( host, > :password=>'candy', > :port=>22, > :username=>'ljkid' > ) do |session| > cmd = 'sudo chmod 777 /apps/mystuff/images' > session.process.popen3(cmd) do |stdin,stdout,stderr| > puts stdout.read > end > > end Why bother with Net::SSH? require 'open3' Open3.popen3 "ssh hostname sudo ls" do |i,o,e| i.puts "your password" puts o.read end PS: I hope that isn't your password -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars