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

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
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 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.
You are progressing very well indeed. You seem very well suited to this technology, and to Forums participation. You have provided information when requested, and you have obviously done your homework before asking questions. It is a pleasure to help you. Please continue to ask questions. (I'm no smarter than you are, I've simply been doing this longer).

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.
neskweek
First post
Posts: 1
Joined: Thu Apr 13, 2017 4:26 pm

Re: Adding directory to path

Post by neskweek »

Everything in this thread and in the wiki link is totally outdated.

Modifications in /etc/profile doesn't survive to a reboot.
/etc/init.d/Optware.sh doesn't exist.

The wiki indicates how to install on v3.8, we are on v4.3.

I do undesrtand the security issues with this, but seriuosly : I almost got locked away my own device by just changing my shell to zsh in /etc/password.
After the next reboot link to /usr/bin got wiped out (so /usr/bin/zsh did goes away) and every .zsh* config file got wiped out from /root.
...

And of course nothing is documented anywhere.
Don't get me wrong: that last point is what that is annoying me the most !
User avatar
MrVideo
Experience counts
Posts: 4742
Joined: Fri May 03, 2013 2:26 pm

Re: Adding directory to path

Post by MrVideo »

neskweek wrote:I do undesrtand the security issues with this, but seriuosly : I almost got locked away my own device by just changing my shell to zsh in /etc/password.
After the next reboot link to /usr/bin got wiped out (so /usr/bin/zsh did goes away) and every .zsh* config file got wiped out from /root.
...
Because you do not use /root:

Code: Select all

admin:x:0:0:administrator:/share/homes/admin:/bin/bash
zadmin:x:0:0:administrator:/share/homes/admin:/opt/bin/zsh
QTS MANUALS
Submit QNAP Support Ticket - QNAP Tutorials, FAQs, Downloads, Wiki - Product Support Status - Moogle's QNAP FAQ help V2
Asking a question, include the following
(Thanks to Toxic17)
QNAP md_checker nasreport (release 20210309)
===============================
Model: TS-869L -- RAM: 3G -- FW: QTS 4.1.4 Build 20150522 (used for data storage)
WD60EFRX-68L0BN1(x1)/68MYMN1(x7) Red HDDs -- RAID6: 8x6TB -- Cold spare: 1x6TB
Entware
===============================
Model: TS-451A -- RAM: 2G -- FW: QTS 4.5.2 Build 20210202 (used as a video server)
WL3000GSA6472(x3) White label NAS HDDs -- RAID5: 3x3TB
Entware -- MyKodi 17.3 (default is Kodi 16)
===============================
My 2017 Total Solar Eclipse Photos | My 2019 N. Ireland Game of Thrones tour
alexraio
First post
Posts: 1
Joined: Sat Mar 21, 2015 10:59 pm

Re: Adding directory to path

Post by alexraio »

So... here what I think is the easier way to solve the problem:

1. install Entware
2. edit /opt/etc/profile and add something like this:

Code: Select all

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

    if [ "$BASH" ]; then
        export PS1="[\u@\h \W]\\$ "
    else
      if [ "`id -u`" -eq 0 ]; then
        export PS1='# '
      else
        export PS1='$ '
      fi
    fi

    export USER=`id -un`
    export LOGNAME=$USER
    export HOSTNAME=`/bin/hostname`
    export HISTSIZE=10000
    export HISTFILESIZE=10000
    export HISTFILE=/share/homes/admin/.bash_history ### IMPORTANT: This permit you to change the history Path were .bash_history will be saved.
    export PAGER='/bin/more '
    export EDITOR='/bin/vi'
    export INPUTRC=/etc/inputrc
    export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
    export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;
31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.png=01;35:*.gif=01;35:*.bmp=01;35:*.
pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.x
cf=01;35:*.xwd=01;35:';

    ### Some aliases
    alias ps2='ps facux '
    alias ps1='ps faxo "%U %t %p %a" '
    alias af='ps af'
    alias cls='clear'
    alias ll='/bin/ls -laFh'
    alias ls='/bin/ls -F'
    alias df='df -h'
    alias indent='indent -bad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -npsl -nsc -nsob -nss -
ts4 '
    #alias bc='bc -l'
    alias minicom='minicom -c on'
    alias calc='calc -Cd '
    alias bc='calc -Cd '
fi;
3. edit /opt/Entware-ng.sh
a. change:

Code: Select all

# adding opkg apps into system path ...
/bin/cat /root/.profile | /bin/grep "source" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "source /opt/etc/profile" > /root/.bash_profile
with:

Code: Select all

# adding opkg apps into system path ...
        /bin/cat /root/.bash_profile | /bin/grep "source" 1>>/dev/null 2>>/dev/null
        [ $? -ne 0 ] && /bin/echo "source /opt/etc/profile" > /root/.bash_profile
b. change:

Code: Select all

  stop)
        /bin/echo "Disable Entware-ng/opkg"
        /opt/etc/init.d/rc.unslung stop
        /bin/sed -i '/source \/opt\/etc\/profile/d' /root/.profile
        /bin/sync
        /bin/sleep 1
        ;;
with:

Code: Select all

  stop)
        /bin/echo "Disable Entware-ng/opkg"
        /opt/etc/init.d/rc.unslung stop
        /bin/sed -i '/source \/opt\/etc\/profile/d' /root/.bash_profile
        /bin/sync
        /bin/sleep 1
        ;;
4. Done

!!! Important as comprehension:

in /root there are a lot of hidden files that are always overwritten when QNAP is restarted, Like:
.bash_history
.bash_logout
.bash_profile
.bashrc
.profile

every restart this files are recreated the point is that if .bash_profile is there it will be read at first and .profile will not be read anymore.
When Entware-ng.sh is started at the boot process it create the necessary thing in .bash_profile that will be sourced in a interactive login shell.

From now on the history and opkg PATH will be kept.

I hope it was helpful.
bruce_miranda
Getting the hang of things
Posts: 94
Joined: Mon Jul 03, 2017 6:53 am

Re: Adding directory to path

Post by bruce_miranda »

I realise this is an old thread. However I have a related question. I have modified the scripts so that /etc/profile get updated everytime I boot up the NAS and login via SSH. The PATH is exactly how I need it when I log in via SSH. However job that are running on the crontab don't appear to be using my modified path. The issue here is that there are two python installations, one that comes as part of the firmware - which is very old and doesn't have a lot of modules included. The Python that is installed via the App Manager is fine but without setting the PATH, my scripts can't use it. So I am stuck.

How do I set the PATH for the system and the non interactive users?

My original issue is listed here.
viewtopic.php?f=217&t=137078&p=644393#p644393
NAS : TVS-471
CPU : i7-4790T
RAM : 16GB
HDD : 2 x 10TB + 1 x 6TB + 1 x 4TB
SSD : 2 x 500GB (used for SSD Cache)
User avatar
MrVideo
Experience counts
Posts: 4742
Joined: Fri May 03, 2013 2:26 pm

Re: Adding directory to path

Post by MrVideo »

Crontab scripts do not use any of those settings for the path, since it is not interactive. Whatever script is run by crontab must contain the path you want set, or the script can source a file that contains the desired path.
QTS MANUALS
Submit QNAP Support Ticket - QNAP Tutorials, FAQs, Downloads, Wiki - Product Support Status - Moogle's QNAP FAQ help V2
Asking a question, include the following
(Thanks to Toxic17)
QNAP md_checker nasreport (release 20210309)
===============================
Model: TS-869L -- RAM: 3G -- FW: QTS 4.1.4 Build 20150522 (used for data storage)
WD60EFRX-68L0BN1(x1)/68MYMN1(x7) Red HDDs -- RAID6: 8x6TB -- Cold spare: 1x6TB
Entware
===============================
Model: TS-451A -- RAM: 2G -- FW: QTS 4.5.2 Build 20210202 (used as a video server)
WL3000GSA6472(x3) White label NAS HDDs -- RAID5: 3x3TB
Entware -- MyKodi 17.3 (default is Kodi 16)
===============================
My 2017 Total Solar Eclipse Photos | My 2019 N. Ireland Game of Thrones tour
dulcifium
Been there, done that
Posts: 720
Joined: Fri Oct 23, 2009 6:52 pm

Re: Adding directory to path

Post by dulcifium »

bruce_miranda wrote:I have modified the scripts so that /etc/profile get updated everytime I boot up the NAS and login via SSH. The PATH is exactly how I need it when I log in via SSH.
Please can you explain exactly how you did this so i don't have to run

Code: Select all

export PATH=/opt/bin:/opt/sbin:$PATH
every time I start an SSH session?

Thanks :)
QNAP TS-639 Pro (3.8.1 Build 20121205) | 6 x 3 TB (Toshiba DT01ACA300 firmware MX6OABB0) | 12 TB RAID-6
Both shared over single port GbE and wifi router to Linux, Android, Windows, macOS and NVIDIA Shield
Post Reply

Return to “System & Disk Volume Management”