Adding directory to path

Questions about SNMP, Power, System, Logs, disk, & RAID.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Adding directory to path

Post 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
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post by Phifer »

Thank you. I will look into this and try it out.
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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?
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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.
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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?
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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.
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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[/url] section of [url=http://wiki.qnap.com/wiki/]QNAPedia[/url] article: [url=http://wiki.qnap.com/wiki/Install_Optware_IPKG]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

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Adding directory to path

Post 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.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Adding directory to path

Post 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.
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
Post Reply

Return to “System & Disk Volume Management”