ruby edit sudo file

Hello friends

I am trying to edit apache2 https.config file which require sudo permission through my ruby scripting.

File.open(local_filename, ‘a’) { |f| f.write(doc) }

I can open and edit normal file which doesn’t require sudo permission.

I am searching around two hours but still not find any solution, Can anyone suggest any idea or any links?

Thanks

Be very very careful with this. It can easily leave you wide open to a hack.

Assuming you do really mean a ruby script, and nothing in your Rails app,
you can set the setuid bit with chmod and chown the script to root. When it
executes, it will execute with root persmissions.

Given you've not been able to find this information yourself, I'd again
caution you not to do this.

I am using the below command and now its not asking password but i think its not a secure way…

system(“echo systempassword | sudo -S ruby example.rb”)
example.rb:

in this .rb file i am opening my apache2 file and editing successfully using ruby File class.

Please don’t reply on top (top post). Reply at the bottom so the conversation can be followed easier.