Announcement

Collapse
No announcement yet.

<SOLVED> cannot execute ruby interpreter from root

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    <SOLVED> cannot execute ruby interpreter from root

    I suspect that this is a simple problem, and hard for me only because of my modest (!) grasp of Linux basics. Here goes:

    I program exclusively in Ruby. I want to execute a Unison script which is run from within a Ruby program, then turn off my computer. The Unison thing simply matches up my on-board HD with an external USB HD I use on another machine. It runs for a while, then I want my computer to shutdown. I'm using the 'shutdown' command to effect that. The idea is to set this running and go to bed. A few minutes later it's done and the computer is off.

    "Shutdown' must be run from my admin. acct., of course. But when I enter 'sudo ruby unison.rb' (that's the name of my ruby script), I'm told that Ruby isn't installed. When I start an admin. Konsole and try 'ruby unison.rb' I get the same result. Checking the permissions on the ruby binary (I compiled this myself), it's clearly owned by root. It runs just fine from my normal user acct.

    So, why doesn't root know about it? What do I need to do to get this simple thing to run? I'm out of ideas at this point. (Yeah, I know I could be using a bash script to do this, but I don't know bash, and this is very easy to set up in ruby...if it would run.)

    Any help would be gratefully received.

    t.

    #2
    Re: cannot execute ruby interpreter from root

    Originally posted by tomcloyd
    ...
    So, why doesn't root know about it?
    ...
    the most obvious thing is that ruby is installed in a directory that is not in root's "path" environment variable.
    if you installed ruby from the repos, then this should not be your problem.
    if you installed manually, then it might.
    in any case, it is easy to find out.

    start a konsole and, as your regular user, type:
    Code:
    which ruby
    then do it again as user root
    Code:
    sudo -i
    which ruby
    see if the ruby interpreter is found alright in both environments.

    if it is, then check your unison script...
    you're executing ruby from the command line (i.e. interactively).
    so i assume there is no
    Code:
    #!/usr/bin/ruby
    at the start (i.e. on the 1st line) of the script file.
    but it's worth checking.
    if you have that line, and the path is incorrect, then you could see that sort of problem.

    another thing you could do is use absolute paths to both ruby and your script.
    like so
    Code:
    sudo /absolute/path/to/ruby /absolute/path/to/script.rb
    hth

    ps:
    out of curiosity...
    is "admin.acct." the actual name of your administration account?
    if it is, be aware "." (i.e. dots) are illegal in user names (together with a bunch of other chars).
    gnu/linux is not windoze

    Comment


      #3
      Re: cannot execute ruby interpreter from root

      Oh man, I had no idea how little I understood things. I'm in freefall here.

      Yes, I have a path problem, but right away I cannot make sense of things (I'm putting comments/questions in double angle brackets, below):

      Code:
      tomc@tomc-laptop:~$ echo $PATH
      /opt/ruby/1.8.7-p160/bin:/home/tomc/.gem/ruby/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
      
      tomc@tomc-laptop:~$ sudo -i
      [sudo] password for tomc:
      <<"tomc"??? Have never noticed this before, although I suspect it's always been there. "tomc" is, 
      I thought, my non-root user acct. - so why does it as for my "tomc" password when I'm trying to get
      into root? On the other hand, I'm not aware of ever setting up a password for root, which I thought was my 
      default admin. acct. I always just give my acct. password at this point and suddenly get to root. I suddenly 
      cannot make any sense of this. >>
      
      root@tomc-laptop:~# echo $PATH
      /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
      <<That's plainly NOT a path that will allow ruby to run.>>
      You ask, at the end of your reply, what the name of my admin. acct. is. I've never set up one that I know of, and have no idea what its name is. It's NOT "admin.acct", certainly.

      Normally, to modify my path, I fire up a root kate, with "sudo kate", then edit "/etc/environment". I've never know that there was more than one path, until now. I have NO idea how to find or edit any other path but the one referred to in that file, the contents of which is this:

      Code:
      PATH="/opt/ruby/1.8.7-p160/bin:/home/tomc/.gem/ruby/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
      What's my next move? I thought "root" WAS my admin. acct., but I don't see where a separate path might be established for it. And, when at the "#" (root) prompt, I note that I CANNOT launch either Kate or Dolphin. I have no idea why. Root suddenly looks rather useless. I know I CAN get a kate or dolphin with admin. access by entering "sudo kate", etc, at a CLI, so why, when I'm already in root, is "kate" suddenly unknown. None of this makes any sense to me. I have a path problem in an acct. whose name I don't know, and I don't know where the path IS, nor could I launch an editor to modifiy it if I did. Whew.

      Can you possibly pull me out of this black whole of ignorance I seem mired in? Is there some succinct general orientation to Linux accts. somewhere which I ought to go look at? (I do not have the time to take a course, or plow through some large book. Life is short and I have work to do, sad to say).

      Thanks for any help you can offer.

      Comment


        #4
        Re: cannot execute ruby interpreter from root

        Originally posted by jankushka
        if you installed ruby from the repos, then this should not be your problem.
        I program in Ruby too, so I tried sudo ruby and I have no problem with it. I installed Ruby from the repository.
        Kubuntu 16.04 on two computers and Kubuntu 17.04 on DELL Latitude 13

        Comment


          #5
          Re: cannot execute ruby interpreter from root

          You are making a common mistake. Your problem is "sudo -i" not your path.

          http://www.faqs.org/docs/Linux-mini/Path.html#ss7.2

          I would at least read over the first 7 sections in the How-to then come back here if you need further guidance. It's a quick read.
          linux &amp;&amp; bash = &quot;the future&quot;

          Comment


            #6
            Re: cannot execute ruby interpreter from root

            i shall suggest the following:
            a) remove your manual installation of ruby
            b) install ruby from the repositories
            that will solve your issues about running your ruby script.
            if you install things from the repos, dependencies and configuration issues will be taken care of for you.
            why not using such a powerful tool?

            as for the root/non-root account thing.
            it's one of the fundamental distinctions of ubuntu linux.
            the "root" account is disabled by default.
            regular users can be given the privilege to substitute their identity to do things as someone else.
            this is done through the substitute user do (i.e. sudo) mechanism.
            the default substituted user is "root".
            and access to the substitution is achieved (in ubuntu systems) by giving one's own password.
            in ubuntu systems all users that belong to group "admin" have access to sudo.
            users configured at installation time are made part of group "admin" by default.

            hth
            gnu/linux is not windoze

            Comment


              #7
              Re: cannot execute ruby interpreter from root

              Originally posted by ukchucktown
              You are making a common mistake. Your problem is "sudo -i" not your path.

              http://www.faqs.org/docs/Linux-mini/Path.html#ss7.2

              I would at least read over the first 7 sections in the How-to then come back here if you need further guidance. It's a quick read.
              Arrrgh! Enlightenment. Thanks for the nudge. Will study up a bit. Very helpful!

              Comment


                #8
                Re: cannot execute ruby interpreter from root

                Originally posted by jankushka
                i shall suggest the following:
                a) remove your manual installation of ruby
                b) install ruby from the repositories
                that will solve your issues about running your ruby script.
                if you install things from the repos, dependencies and configuration issues will be taken care of for you.
                why not using such a powerful tool?
                1. It's a good skill to have - manual compilation. I need the practice.
                2. Manual compilation of the ruby interpreter allows me to get exactly the flavor I want. The generic flavor in the repository is [a] not always uptodate, and [2] often set up with flags for options I don't use which make it run slower.

                Of course, there can be downsides (!).

                It's always a critical decision to make - how close to the earth to live (or in this case, close to the computer). Sometimes all those interfaces are just hugely practical. Other times, they keep you from learning things you do better to learn. At the moment, I think I'm getting more out of this little problem than it's costing me. Other times, that isn't the case at all.

                as for the root/non-root account thing.
                it's one of the fundamental distinctions of ubuntu linux.
                the "root" account is disabled by default.
                regular users can be given the privilege to substitute their identity to do things as someone else.
                this is done through the substitute user do (i.e. sudo) mechanism.
                the default substituted user is "root".
                and access to the substitution is achieved (in ubuntu systems) by giving one's own password.
                in ubuntu systems all users that belong to group "admin" have access to sudo.
                users configured at installation time are made part of group "admin" by default.

                hth
                That's fundamentally helpful for me to know. I need to learn a bit more about this, but your summary gives me key concepts to explore, and I'll do so. Thanks for such a nice little synopsis!

                t,

                Comment


                  #9
                  Re: cannot execute ruby interpreter from root

                  Have been reading and trying a number of things, and I still don't have a solution. Nothing I'm learning appears to address the problem I have.

                  I want to have a Ruby script run some system commands (no problem there), then execute the "shutdown" command (big problem).

                  Apparently, only root gets to do that, and to get root privileges, one has to use "sudo", but I don't see a way to do that in a script, because I have to give a password. It appears to be inalterably an interactive command. If I use "su -i" to get a root level terminal, access to the shutdown command disappears. This is nuts.

                  I just want to run a program the have my computer turn off.

                  Can anyone show me the short path to this objective?

                  Comment


                    #10
                    Re: cannot execute ruby interpreter from root

                    Originally posted by tomcloyd
                    Can anyone show me the short path to this objective?
                    Sure. Grant the user account running the Ruby application permission to shut down the system.

                    we see things not as they are, but as we are.
                    -- anais nin

                    Comment


                      #11
                      Re: cannot execute ruby interpreter from root

                      And you grant users permission in the /etc/sudoers file. Let's assume your user name is tomcloyd and your host name is tom.server.com.

                      All of this is explained in the sudoers man page (man sudoers). You need a line like the one below in your sudoers file for the user you want
                      to shutdown the system.

                      You specify the user(s), server(s) where the user has the permission (can be one or more and different formats are supported including IP address),
                      equal sign then the command(s) separated by commas. Hope that helps.

                      Code:
                      tomcloyd tom.server.com = /sbin/shutdown
                      linux &amp;&amp; bash = &quot;the future&quot;

                      Comment


                        #12
                        Re: cannot execute ruby interpreter from root

                        I've spent a costly amount of time on this, but I'm not there yet. Need help with that final 10 feet.

                        First, ukchucktown, thanks for the help. Without your post I'd have had no idea how to act on the previous posts suggestion. After wading into the morass that is 'man sudoers' (gak!), and multiple attempts to edit my /etc/sudoers file, I'm still being told that I have to be root to execute shutdown. Unless I make a career of studying 'man sudoers' I'm not going to get this. Here's the details:

                        My sudoers file:

                        Code:
                        # /etc/sudoers
                        #
                        # This file MUST be edited with the 'visudo' command as root.
                        #
                        # See the man page for details on how to write a sudoers file.
                        #
                        
                        Defaults	env_reset 
                        Defaults	insults
                        
                        # Host alias specification
                        
                        # User alias specification
                        
                        # Cmnd alias specification
                        
                        # User privilege specification
                        tomc tomc-laptop = NOPASSWD: /sbin/shutdown
                        root	ALL=(ALL) ALL
                        
                        # Uncomment to allow members of group sudo to not need a password
                        # (Note that later entries override this, so you might need to move
                        # it further down)
                        # %sudo ALL=NOPASSWD: ALL
                        
                        # Members of the admin group may gain root privileges
                        %admin ALL=(ALL) ALL
                        I call your attention to this section:
                        Code:
                        # User privilege specification
                        tomc tomc-laptop = NOPASSWD: /sbin/shutdown
                        root	ALL=(ALL) ALL
                        The second line is my modification. NOPASSWD option is a late, desperate addition. It didn't have any discernible effect. This is the result I still get:

                        Code:
                        tomc@tomc-laptop:~$ shutdown -P now
                        shutdown: Need to be root
                        tomc@tomc-laptop:~$
                        I really don't see the problem. My reading of man sudoer tells me I'm doing it right. Linux doesn't. Can anyone offer a suggestion as to my error?

                        Thanks.

                        Comment


                          #13
                          Re: cannot execute ruby interpreter from root

                          i might be wrong, but i see 2 issues:

                          a) you assume that adding that entry to /etc/sudoers will allow user tomc on tomc-laptop to run shutdown as root.
                          this is not correct.
                          that entry tells sudo not to ask for a password when user tomc on tomc-laptop issues "sudo shutdown".
                          it's sudo that allows tomc to gain root privileges.
                          you still have to use sudo.

                          b) out of the sudo man page (in the description section, at the top)
                          ...
                          When multiple entries match for a user, they are applied in order.
                          Where there are multiple matches, the last match is used
                          (which is not necessarily the most specific match).
                          ...
                          that is, your line would have no effect whatsoever, since the last line
                          ...
                          # Members of the admin group may gain root privileges
                          %admin ALL=(ALL) ALL
                          would override it, anyway.

                          so, to make things work, you should:
                          a) move you conf line to the bottom of /etc/sudoers
                          b) change your call, in your script, or wherever, to "sudo /sbin/shutdown ..."

                          hth

                          ps:
                          Originally posted by tomcloyd
                          ...
                          My reading of man sudoer tells me I'm doing it right. Linux doesn't.
                          ...
                          that is hardly ever the case
                          i mean...that linux doesn't do things right...
                          gnu/linux is not windoze

                          Comment


                            #14
                            Re: cannot execute ruby interpreter from root

                            Thanks for your suggestions. Sounds good, and will give it shot after a little sleep. I'm hopeful (ever the fool).

                            Re: "ps" - all I was trying to was that I thought I was on track, but Linux said I wasn't. Pigs will fly the day I think I've caught Linux in a screwup. That's for them what know far more than do I.

                            Comment


                              #15
                              Re: &lt;SOLVED&gt; cannot execute ruby interpreter from root

                              jankushka - IT WORKS! My standalone cleanup and shutdown ruby program now does just what I want. Thanks for giving me that final helpful push. Couldn't be more pleased. ~.t

                              Comment

                              Working...
                              X