need help. want to use Net::sh to do sudo command

W

wbsurfver

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
 
E

Eric Hodel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top