ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Newb question - Running a script from the root directory

    IT Discussion
    scripts centos centos7 linux education
    7
    29
    4.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DustinB3403D
      DustinB3403 @scottalanmiller
      last edited by DustinB3403

      @scottalanmiller said in Newb question - Running a script from the root directory:

      @dustinb3403 said in Newb question - Running a script from the root directory:

      @stacksofplates said in Newb question - Running a script from the root directory:

      @dustinb3403 said in Newb question - Running a script from the root directory:

      @danp said in Newb question - Running a script from the root directory:

      Is the directory in your path? What do you get from echo $PATH?

      echo $PATH
      /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

      I've added it (twice).

      Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

      source ~/.bash_profile
      

      I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

      By simply moving the script into an already existing path, I am able to update with just "script.sh".

      When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

      Remember that ~ is a shortcut to your home directory, which is /root

      So by adding /opt/scripts/ this would've worked, but would've added complexity for no reason.

      scottalanmillerS stacksofplatesS 2 Replies Last reply Reply Quote 0
      • scottalanmillerS
        scottalanmiller @DustinB3403
        last edited by

        @dustinb3403 said in Newb question - Running a script from the root directory:

        @scottalanmiller said in Newb question - Running a script from the root directory:

        @dustinb3403 said in Newb question - Running a script from the root directory:

        @stacksofplates said in Newb question - Running a script from the root directory:

        @dustinb3403 said in Newb question - Running a script from the root directory:

        @danp said in Newb question - Running a script from the root directory:

        Is the directory in your path? What do you get from echo $PATH?

        echo $PATH
        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

        I've added it (twice).

        Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

        source ~/.bash_profile
        

        I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

        By simply moving the script into an already existing path, I am able to update with just "script.sh".

        When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

        Remember that ~ is a shortcut to your home directory, which is /root

        So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

        Why so many quotes?

        Yes, /opt/scripts would work, /root/opt/scripts does, too. Neither is a good location.

        DustinB3403D 1 Reply Last reply Reply Quote 1
        • stacksofplatesS
          stacksofplates @DustinB3403
          last edited by

          @dustinb3403 said in Newb question - Running a script from the root directory:

          @scottalanmiller said in Newb question - Running a script from the root directory:

          @dustinb3403 said in Newb question - Running a script from the root directory:

          @stacksofplates said in Newb question - Running a script from the root directory:

          @dustinb3403 said in Newb question - Running a script from the root directory:

          @danp said in Newb question - Running a script from the root directory:

          Is the directory in your path? What do you get from echo $PATH?

          echo $PATH
          /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

          I've added it (twice).

          Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

          source ~/.bash_profile
          

          I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

          By simply moving the script into an already existing path, I am able to update with just "script.sh".

          When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

          Remember that ~ is a shortcut to your home directory, which is /root

          So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

          No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

          DustinB3403D 1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403 @scottalanmiller
            last edited by

            @scottalanmiller said in Newb question - Running a script from the root directory:

            @dustinb3403 said in Newb question - Running a script from the root directory:

            @scottalanmiller said in Newb question - Running a script from the root directory:

            @dustinb3403 said in Newb question - Running a script from the root directory:

            @stacksofplates said in Newb question - Running a script from the root directory:

            @dustinb3403 said in Newb question - Running a script from the root directory:

            @danp said in Newb question - Running a script from the root directory:

            Is the directory in your path? What do you get from echo $PATH?

            echo $PATH
            /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

            I've added it (twice).

            Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

            source ~/.bash_profile
            

            I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

            By simply moving the script into an already existing path, I am able to update with just "script.sh".

            When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

            Remember that ~ is a shortcut to your home directory, which is /root

            So by adding /opt/scripts/ this would've worked, but would've added complexity for no reason.

            Why so many quotes?

            Yes, /opt/scripts would work, /root/opt/scripts does, too. Neither is a good location.

            Grr those aren't quotes those are the red code markdown.... and I added to many.... sorry typo error.

            1 Reply Last reply Reply Quote 0
            • DustinB3403D
              DustinB3403 @stacksofplates
              last edited by DustinB3403

              @stacksofplates said in Newb question - Running a script from the root directory:

              @dustinb3403 said in Newb question - Running a script from the root directory:

              @scottalanmiller said in Newb question - Running a script from the root directory:

              @dustinb3403 said in Newb question - Running a script from the root directory:

              @stacksofplates said in Newb question - Running a script from the root directory:

              @dustinb3403 said in Newb question - Running a script from the root directory:

              @danp said in Newb question - Running a script from the root directory:

              Is the directory in your path? What do you get from echo $PATH?

              echo $PATH
              /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

              I've added it (twice).

              Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

              source ~/.bash_profile
              

              I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

              By simply moving the script into an already existing path, I am able to update with just "script.sh".

              When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

              Remember that ~ is a shortcut to your home directory, which is /root

              So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

              No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

              Originally I created the directory /opt/scripts and put the script in there so the Directory looked like

              /opt/scripts/script.sh

              I went back and change the script location to be in /usr/local/bin

              So in /usr/local/bin I now have script.sh

              This now works without issue, and /opt/scripts no longer exists.

              stacksofplatesS 1 Reply Last reply Reply Quote 1
              • stacksofplatesS
                stacksofplates @DustinB3403
                last edited by stacksofplates

                @dustinb3403 said in Newb question - Running a script from the root directory:

                @stacksofplates said in Newb question - Running a script from the root directory:

                @dustinb3403 said in Newb question - Running a script from the root directory:

                @scottalanmiller said in Newb question - Running a script from the root directory:

                @dustinb3403 said in Newb question - Running a script from the root directory:

                @stacksofplates said in Newb question - Running a script from the root directory:

                @dustinb3403 said in Newb question - Running a script from the root directory:

                @danp said in Newb question - Running a script from the root directory:

                Is the directory in your path? What do you get from echo $PATH?

                echo $PATH
                /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                I've added it (twice).

                Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                source ~/.bash_profile
                

                I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                By simply moving the script into an already existing path, I am able to update with just "script.sh".

                When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                Remember that ~ is a shortcut to your home directory, which is /root

                So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                /opt/scripts/script.sh

                I went back and change the script location to be in /usr/local/bin

                So in /usr/local/bin I now have script.sh

                This now works without issue, and /opt/scripts no longer exists.

                Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shell config you’re using) it would have worked. But you still have to let the user know of the PATH change.

                DustinB3403D 1 Reply Last reply Reply Quote 0
                • stacksofplatesS
                  stacksofplates
                  last edited by

                  Also what’s up with the giant red plus button right where you’re typing on mobile now?

                  1 Reply Last reply Reply Quote 0
                  • DustinB3403D
                    DustinB3403 @stacksofplates
                    last edited by

                    @stacksofplates said in Newb question - Running a script from the root directory:

                    @dustinb3403 said in Newb question - Running a script from the root directory:

                    @stacksofplates said in Newb question - Running a script from the root directory:

                    @dustinb3403 said in Newb question - Running a script from the root directory:

                    @scottalanmiller said in Newb question - Running a script from the root directory:

                    @dustinb3403 said in Newb question - Running a script from the root directory:

                    @stacksofplates said in Newb question - Running a script from the root directory:

                    @dustinb3403 said in Newb question - Running a script from the root directory:

                    @danp said in Newb question - Running a script from the root directory:

                    Is the directory in your path? What do you get from echo $PATH?

                    echo $PATH
                    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                    I've added it (twice).

                    Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                    source ~/.bash_profile
                    

                    I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                    By simply moving the script into an already existing path, I am able to update with just "script.sh".

                    When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                    Remember that ~ is a shortcut to your home directory, which is /root

                    So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                    No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                    Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                    /opt/scripts/script.sh

                    I went back and change the script location to be in /usr/local/bin

                    So in /usr/local/bin I now have script.sh

                    This now works without issue, and /opt/scripts no longer exists.

                    Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                    I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                    Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                    stacksofplatesS 1 Reply Last reply Reply Quote 0
                    • stacksofplatesS
                      stacksofplates @DustinB3403
                      last edited by

                      @dustinb3403 said in Newb question - Running a script from the root directory:

                      @stacksofplates said in Newb question - Running a script from the root directory:

                      @dustinb3403 said in Newb question - Running a script from the root directory:

                      @stacksofplates said in Newb question - Running a script from the root directory:

                      @dustinb3403 said in Newb question - Running a script from the root directory:

                      @scottalanmiller said in Newb question - Running a script from the root directory:

                      @dustinb3403 said in Newb question - Running a script from the root directory:

                      @stacksofplates said in Newb question - Running a script from the root directory:

                      @dustinb3403 said in Newb question - Running a script from the root directory:

                      @danp said in Newb question - Running a script from the root directory:

                      Is the directory in your path? What do you get from echo $PATH?

                      echo $PATH
                      /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                      I've added it (twice).

                      Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                      source ~/.bash_profile
                      

                      I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                      By simply moving the script into an already existing path, I am able to update with just "script.sh".

                      When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                      Remember that ~ is a shortcut to your home directory, which is /root

                      So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                      No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                      Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                      /opt/scripts/script.sh

                      I went back and change the script location to be in /usr/local/bin

                      So in /usr/local/bin I now have script.sh

                      This now works without issue, and /opt/scripts no longer exists.

                      Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                      I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                      Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                      I mean you have to let the user you are logged in as Know if the change. Either by logging out and back in or by temporarily sourcing the config.

                      DustinB3403D 1 Reply Last reply Reply Quote 0
                      • DustinB3403D
                        DustinB3403 @stacksofplates
                        last edited by

                        @stacksofplates said in Newb question - Running a script from the root directory:

                        @dustinb3403 said in Newb question - Running a script from the root directory:

                        @stacksofplates said in Newb question - Running a script from the root directory:

                        @dustinb3403 said in Newb question - Running a script from the root directory:

                        @stacksofplates said in Newb question - Running a script from the root directory:

                        @dustinb3403 said in Newb question - Running a script from the root directory:

                        @scottalanmiller said in Newb question - Running a script from the root directory:

                        @dustinb3403 said in Newb question - Running a script from the root directory:

                        @stacksofplates said in Newb question - Running a script from the root directory:

                        @dustinb3403 said in Newb question - Running a script from the root directory:

                        @danp said in Newb question - Running a script from the root directory:

                        Is the directory in your path? What do you get from echo $PATH?

                        echo $PATH
                        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                        I've added it (twice).

                        Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                        source ~/.bash_profile
                        

                        I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                        By simply moving the script into an already existing path, I am able to update with just "script.sh".

                        When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                        Remember that ~ is a shortcut to your home directory, which is /root

                        So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                        No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                        Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                        /opt/scripts/script.sh

                        I went back and change the script location to be in /usr/local/bin

                        So in /usr/local/bin I now have script.sh

                        This now works without issue, and /opt/scripts no longer exists.

                        Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                        I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                        Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                        I mean you have to let the user you are logged in as Know if the change. Either by logging out and back in or by temporarily sourcing the config.

                        I've logged out, what do you mean "sourcing the config" ?

                        stacksofplatesS 1 Reply Last reply Reply Quote 0
                        • stacksofplatesS
                          stacksofplates @DustinB3403
                          last edited by stacksofplates

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @stacksofplates said in Newb question - Running a script from the root directory:

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @stacksofplates said in Newb question - Running a script from the root directory:

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @stacksofplates said in Newb question - Running a script from the root directory:

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @scottalanmiller said in Newb question - Running a script from the root directory:

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @stacksofplates said in Newb question - Running a script from the root directory:

                          @dustinb3403 said in Newb question - Running a script from the root directory:

                          @danp said in Newb question - Running a script from the root directory:

                          Is the directory in your path? What do you get from echo $PATH?

                          echo $PATH
                          /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                          I've added it (twice).

                          Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                          source ~/.bash_profile
                          

                          I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                          By simply moving the script into an already existing path, I am able to update with just "script.sh".

                          When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                          Remember that ~ is a shortcut to your home directory, which is /root

                          So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                          No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                          Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                          /opt/scripts/script.sh

                          I went back and change the script location to be in /usr/local/bin

                          So in /usr/local/bin I now have script.sh

                          This now works without issue, and /opt/scripts no longer exists.

                          Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                          I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                          Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                          I mean you have to let the user you are logged in as Know if the change. Either by logging out and back in or by temporarily sourcing the config.

                          I've logged out, what do you mean "sourcing the config" ?

                          If you change your PATH while you’re logged on the user account doesn’t know of that change. You have to either log out and log in again or temporarily do something like

                          source ~/.bashrc
                          
                          DustinB3403D scottalanmillerS 2 Replies Last reply Reply Quote 2
                          • DustinB3403D
                            DustinB3403 @stacksofplates
                            last edited by

                            @stacksofplates said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @stacksofplates said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @stacksofplates said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @stacksofplates said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @scottalanmiller said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @stacksofplates said in Newb question - Running a script from the root directory:

                            @dustinb3403 said in Newb question - Running a script from the root directory:

                            @danp said in Newb question - Running a script from the root directory:

                            Is the directory in your path? What do you get from echo $PATH?

                            echo $PATH
                            /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                            I've added it (twice).

                            Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                            source ~/.bash_profile
                            

                            I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                            By simply moving the script into an already existing path, I am able to update with just "script.sh".

                            When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                            Remember that ~ is a shortcut to your home directory, which is /root

                            So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                            No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                            Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                            /opt/scripts/script.sh

                            I went back and change the script location to be in /usr/local/bin

                            So in /usr/local/bin I now have script.sh

                            This now works without issue, and /opt/scripts no longer exists.

                            Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                            I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                            Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                            I mean you have to let the user you are logged in as Know if the change. Either by logging out and back in or by temporarily sourcing the config.

                            I've logged out, what do you mean "sourcing the config" ?

                            If you change your PATHA while you’re logged on the user account doesn’t know of that change. You have to either log out and log in again or temporarily do something like

                            source ~/.bashrc
                            

                            Gotcha. Yeah I logged out and back in, but it's good to know that source ~/.bashrc would do that as well.

                            1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @stacksofplates
                              last edited by

                              @stacksofplates said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @stacksofplates said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @stacksofplates said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @stacksofplates said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @scottalanmiller said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @stacksofplates said in Newb question - Running a script from the root directory:

                              @dustinb3403 said in Newb question - Running a script from the root directory:

                              @danp said in Newb question - Running a script from the root directory:

                              Is the directory in your path? What do you get from echo $PATH?

                              echo $PATH
                              /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/opt/scripts/:/root/opt/scripts

                              I've added it (twice).

                              Well first off you had /root/opt/scripts not /opt/scripts. Second you either have to log out and back in or tell your user to use the new path with something like

                              source ~/.bash_profile
                              

                              I used ````~/opt/scripts``` initially, as I wasn't aware of just adding my scripts into one of the existing locations. (everything said just add a new directory).

                              By simply moving the script into an already existing path, I am able to update with just "script.sh".

                              When you are root and your home is /root and you put ~/opt/scripts that is /root/opt/scripts.

                              Remember that ~ is a shortcut to your home directory, which is /root

                              So by adding ```/opt/scripts/```` this would've worked, but would've added complexity for no reason.

                              No that still isn’t a default location. In the OP you said you put the script in /opt/scripts. Where did you actually put it?

                              Originally I created the directory /opt/scripts and put the script in there so the Directory looks like

                              /opt/scripts/script.sh

                              I went back and change the script location to be in /usr/local/bin

                              So in /usr/local/bin I now have script.sh

                              This now works without issue, and /opt/scripts no longer exists.

                              Ok ya that’s where the problem was. /opt/scripts is different than /root/opt/scripts. If you would have had that in your .bashrc or .bash_profile (or whichever shellconfigure you’re using) it would have worked. But you still have to let the user know of the PATH change.

                              I'm the user in this case, but I never really create / save my own scripts. I just got tired of running a set of commands, every other day.

                              Thus the need to figure out how I could run the script, without having to jump into the exact directory from which the script was saved.

                              I mean you have to let the user you are logged in as Know if the change. Either by logging out and back in or by temporarily sourcing the config.

                              I've logged out, what do you mean "sourcing the config" ?

                              If you change your PATH while you’re logged on the user account doesn’t know of that change. You have to either log out and log in again or temporarily do something like

                              source ~/.bashrc
                              

                              Or the non-aliased version...

                              . ~/.bashrc
                              
                              1 Reply Last reply Reply Quote 1
                              • 1
                              • 2
                              • 2 / 2
                              • First post
                                Last post