Page 1 of 2

Adding directory to path

Posted: Sat Feb 21, 2015 1:04 am
by Phifer
I use the following to add a directory to my path

Code: Select all

PATH=/share/homes/admin/bin:$PATH


I can then run my scripts that are stored there, but after a while it no longer works and I have to run the command again. The system has not even rebooted. Any thoughts?

Thanks

Re: Adding directory to path

Posted: Sat Feb 21, 2015 8:14 am
by pwilson
Phifer wrote:I use the following to add a directory to my path

Code: Select all

PATH=/share/homes/admin/bin:$PATH


I can then run my scripts that are stored there, but after a while it no longer works and I have to run the command again. The system has not even rebooted. Any thoughts?

Thanks


Try this instead:

Code: Select all

export PATH=/share/homes/admin/bin:$PATH


  • Do you have Optware installed?
  • Are you using the QNAP or OpenSSH version of SSHd?


If you are using the OpenSSH server, then you can add this line to your .profile, .bash_profile or .bashrc. If you are still using the QNAP provided one, then you can simply change the $PATH in the /etc/profile instead. See the Fix the $PATH in /etc/profile section of QNAPedia article: Install Optware IPKG.

I hope this information proves useful to you.

Re: Adding directory to path

Posted: Sat Feb 21, 2015 12:37 pm
by Phifer
Thank you. I will look into this and try it out.

Re: Adding directory to path

Posted: Mon Mar 02, 2015 8:28 pm
by Phifer
pwilson wrote:
Try this instead:

Code: Select all

export PATH=/share/homes/admin/bin:$PATH


  • Do you have Optware installed?
  • Are you using the QNAP or OpenSSH version of SSHd?


If you are using the OpenSSH server, then you can add this line to your .profile, .bash_profile or .bashrc. If you are still using the QNAP provided one, then you can simply change the $PATH in the /etc/profile instead. See the Fix the $PATH in /etc/profile section of QNAPedia article: Install Optware IPKG.

I hope this information proves useful to you.

This code worked. I also ran echo $PATH and the results were

Code: Select all

/share/homes/admin/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/opt/bin:/opt/sbin:/usr/local/jre/bin:/Apps/bin:/Apps/sbin

But then after reboot it was no longer listed.
I will need to dig into the wiki you sent me a little more this evening.

I do have Optware installed and these IPKGs

Package: bash
Package: bzip2
Package: diffutils
Package: expat
Package: filebot
Package: git
Package: ipkg-web
Package: libcurl
Package: libdb
Package: libstdc++
Package: nano
Package: ncurses
Package: ncursesw
Package: openssl
Package: py27-setuptools
Package: python26
Package: python27
Package: rcs
Package: readline
Package: sqlite
Package: sudo
Package: unrar
Package: unzip
Package: zlib

Should I install Openssh?

Re: Adding directory to path

Posted: Mon Mar 02, 2015 10:10 pm
by Phifer
I followed the instructions and /opt/bin and opt/sbin are both in the begenning of my PATH even after a restart. I then used
export PATH=/share/homes/admin/bin:$PATH

But after restart the path was cleared again.

I then went to the /etc/ and ran nano on the file "profile". This is what I see:

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login interactive shells.

export PATH=\
/bin:\
/sbin:\
/usr/bin:\
/usr/sbin:\
/usr/bin/X11:\
/usr/local/sbin

# If running interactively, then:
if [ "$PS1" ]; then

    if [ "$BASH" ]; then
        export PS1="[\u@\h \W]\\$ "
        alias ll='/bin/ls -laFh'
        alias ls='/bin/ls -F'
        export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;$
    else
      if [ "`id -u`" -eq 0 ]; then
        export PS1='# '
      else
        export PS1='$ '
      fi
    fi

    export USER=`id -un`


Should I just add "/share/homes/admin/bin:\"

Thank you again for your help. This NAS is definitely got me learning a lot more Linux.

Re: Adding directory to path

Posted: Mon Mar 02, 2015 10:41 pm
by pwilson
Phifer wrote:I use the following to add a directory to my path

Code: Select all

PATH=/share/homes/admin/bin:$PATH


I can then run my scripts that are stored there, but after a while it no longer works and I have to run the command again. The system has not even rebooted. Any thoughts?

Thanks


Please review the Fix the $PATH in /etc/profile section of QNAPedia article: Install Optware IPKG.

If this is set inside your /etc/profile it will be set automatically every time you login, so this should solve the problem for you. You can troubleshoot this by simply checking the setting with:

Code: Select all

echo $PATH

Re: Adding directory to path

Posted: Mon Mar 02, 2015 10:50 pm
by Phifer
Phifer wrote:I followed the instructions and /opt/bin and opt/sbin are both in the begenning of my PATH even after a restart.


I have followed the section: Fix the $PATH in /etc/profile

But my path does not stay after a reboot using

Code: Select all

export PATH=/share/homes/admin/bin:$PATH


So do I need to use my editor (nano) and add it to the profile that way?

Re: Adding directory to path

Posted: Mon Mar 02, 2015 10:57 pm
by pwilson
Phifer wrote:
Phifer wrote:I followed the instructions and /opt/bin and opt/sbin are both in the begenning of my PATH even after a restart.


I have followed the section: Fix the $PATH in /etc/profile

But my path does not stay after a reboot using

Code: Select all

export PATH=/share/homes/admin/bin:$PATH


So do I need to use my editor (nano) and add it to the profile that way?


If it isn't staying then something else is changing it. You'll need to do some troubleshooting to figure out what is changing it. /etc/profile is the first thing run after login, so this does set it. If it is being "unset" by something else, then you'll need to figure out what is changing it.

Re: Adding directory to path

Posted: Tue Mar 03, 2015 12:17 am
by Phifer
Phifer wrote:
So do I need to use my editor (nano) and add it to the profile that way?


I cannot seem to get a yes or no. I have only used the export command. I have not gone through and changed the /etc/profile using my editor in fear of messing something up.

When I use the export PATH=... it does not end up in the /etc/profile

Honestly I have no idea where it does. I know it shows up with echo $PATH until I reboot.

Thank you for your help and patience with the new guy.

Re: Adding directory to path

Posted: Tue Mar 03, 2015 12:27 am
by pwilson
Phifer wrote:
Phifer wrote:
So do I need to use my editor (nano) and add it to the profile that way?


I cannot seem to get a yes or no. I have only used the export command. I have not gone through and changed the /etc/profile using my editor in fear of messing something up.

When I use the export PATH=... it does not end up in the /etc/profile

Honestly I have no idea where it does. I know it shows up with echo $PATH until I reboot.

Thank you for your help and patience with the new guy.


Fix the $PATH in /etc/profile section of QNAPedia article: Install Optware IPKG wrote: Fix the $PATH in /etc/profile

The code that sets up the Optware environment should extend the $PATH environment variable, adding the Optware bin directories to the head of the path where they can preempt any equivalents that come with the QNAP firmware. It should also preserve the original path, with any modifications which other software made. As of April 2010, TS-219P Firmware 3.2.5 build 0409T does not do this correctly.

Edit the file:

Code: Select all

vi /etc/init.d/Optware.sh


Look for the section of code which mentions /opt/bin. Replace it so that this part of the file looks like:

Code: Select all

   # adding Ipkg apps into system path ...
   /bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
        # Bug fix for following: put IPKG first, per http://forum.qnap.com/viewtopic.php?f=124&t=15663
   # was [ $? -ne 0 ] && /bin/echo "export PATH=$PATH":/opt/bin:/opt/sbin >> /etc/profile
   [ $? -ne 0 ] && /bin/echo "export PATH=/opt/bin:/opt/sbin:\$PATH" >> /etc/profile


Save the file and quit the editor.


You can use "nano" instead of "vi" if you feel so inclined.

Code: Select all

/opt/bin/nano /etc/init.d/Optware.sh


Similarly, you probably want to substitute the following code instead of the recommended code:

Code: Select all

   # adding Ipkg apps into system path ...
   /bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
        # Bug fix for following: put IPKG first, per http://forum.qnap.com/viewtopic.php?f=124&t=15663
   # was [ $? -ne 0 ] && /bin/echo "export PATH=$PATH":/opt/bin:/opt/sbin >> /etc/profile
   [ $? -ne 0 ] && /bin/echo "export PATH=/share/homes/admin/bin:/opt/bin:/opt/sbin:\$PATH" >> /etc/profile

Re: Adding directory to path

Posted: Tue Mar 03, 2015 1:06 am
by Phifer
This last post got away from what I am trying to do. I have already done the "Fix the $PATH in /etc/profile"

I am trying to keep my directory in the PATH... /share/homes/admin/bin
This is where I keep my custom scripts.

I have now edited "/etc/profile" and added "/share/homes/admin/bin" to the beginning.
echo $PATH did not show my directory before a reboot or after

Re: Adding directory to path

Posted: Tue Mar 03, 2015 1:21 am
by pwilson
Phifer wrote:This last post got away from what I am trying to do. I have already done the "Fix the $PATH in /etc/profile"

I am trying to keep my directory in the PATH... /share/homes/admin/bin
This is where I keep my custom scripts.

I have now edited "/etc/profile" and added "/share/homes/admin/bin" to the beginning.
echo $PATH did not show my directory before a reboot or after


We're going in circles here. /etc/profile is part of the RAMDisk. It therefore needs to be modified at every boot, this why you change it via the "Optware.sh" file, as clearly shown in my last message in this thread.

Please re-read my previous message for the "exact code" to put in your Optware.sh file. Changes made to /etc/profile won't be active until the next login, so if you modify the /etc/profile file, you need to logout of SSH, and then back in again in order to pick up the changes you made. If you reboot your NAS all changes made to the /etc/profile will disappear.

Re: Adding directory to path

Posted: Tue Mar 03, 2015 1:38 am
by Phifer
Ok.

That is what I was missing was the RAMDisk. Any changes made will be lost. I am now picking up what you were trying to get across. Thanks

Re: Adding directory to path

Posted: Tue Mar 03, 2015 7:23 am
by pwilson
Phifer wrote:Ok.

That is what I was missing was the RAMDisk. Any changes made will be lost. I am now picking up what you were trying to get across. Thanks


If you need further assistance please feel free to ask more questions. I apologize that I was so ineffective at conveying this information sooner. Thank-you for your feedback. I appreciate it. Please me know how you make out.

Re: Adding directory to path

Posted: Tue Mar 03, 2015 10:27 pm
by Phifer
I did get it working and thanks again for your patience. Since I got this system in December I am learning a lot about Linux and command line albeit slowly.