From: Leslie Viljoen Date: 2007-06-13T21:12:58+09:00 Subject: Re: executing sudo from ruby ------=_Part_19646_20450946.1181736778971 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/13/07, anansi wrote: > > hi, > I wanna execute in a script of mine commands like: "sudo apt-get clean" > or "sudo nano /etc/X11/xorg.conf". The difference is: > > The first command needs to be executed without influence to the main > process of the ruby scipt. It should simply be started as a second > process totally independent from the ruby-script which invokes it. > I think system("sudo apt-get clean") would be the right command. > > The second command should be this way that it is the only one after it > has been executed. So the ruby-script should be stopped and therefor in > the same console nano should be opened. > I think exec("sudo nano /etc/X11/xorg.conf") would be the right command. > > But my problem is the password of sudo? How can I make my ruby-scipt > give the password to sudo so I don't have to give it in every time? I am not so clear on what you are asking here, but you can perhaps give a password to sudo via stdin. Here's a line from "man sudo": -S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. To open a pipe to a subprocess, see IO.popen, example near the bottom of this page: http://www.rubycentral.com/book/tut_threads.html I can't comment on the safety of doing this, but it's surely not the worst way to send a password. Les -- > greets > > one must still have chaos in oneself to be able to > give birth to a dancing star > > -- I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did. -- Kent Beck ------=_Part_19646_20450946.1181736778971--