Forum: Ruby "su user -c 'command'" from within ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Moritz R. (Guest)
on 2006-12-24 14:55
(Received via mailing list)
Hi,

I want to invoke a shell command from within ruby but as another user in
a Linux environment. I start the ruby script itself as root and in the
script I do something like this:

%x{su some_user -c "some_command"}

some_more_ruby_stuff

The problem is: 'some_command' gets successfully executed, but the ruby
script seems to never return to normal operation. 'some_more_ruby_stuff'
gets never executed.

Could anyone tell me why this happens and maybe what I could do about
it?

Regards,
Moritz
Wim Vander S. (Guest)
on 2006-12-24 15:21
(Received via mailing list)
Moritz R. wrote:
> The problem is: 'some_command' gets successfully executed, but the ruby
> script seems to never return to normal operation. 'some_more_ruby_stuff'
> gets never executed.
>
> Could anyone tell me why this happens and maybe what I could do about it?
>
> Regards,
> Moritz
>
>
>
It  works just fine here. I tried running this:

    puts %x{su wvdschel -c "whoami"}
    puts "test"

which worked just fine:

    root@wvdschel-laptop:~# ruby test
    wvdschel
    test

Are you sure your command returns? Maybe it blocks until the process
ends? Is there any information you could give on the command you are
trying to execute?

Wim

--
Wim Vander S.
Bachelor Computer Science, University Ghent

http://nanoblog.ath.cx
My weblog, powered by Ruby and BSD licensed.
This topic is locked and can not be replied to.