how do I preserve export PATH?

1

How can I make ssh admin@nas command work if command is in /opt/bin?

On my QNAP NAS File /root/.ssh/rc:

echo "old path is $PATH"
export PATH=/opt/bin:/opt/sbin:$PATH
echo "new path is $PATH"

on my machine:

~$ ssh admin@nas 'echo $PATH'

returns

old path is /usr/bin:/bin:/usr/sbin:/sbin
new path is /opt/bin:/opt/sbin:/usr/bin:/bin:/usr/sbin:/sbin
/usr/bin:/bin:/usr/sbin:/sbin

so the path variable is not preserved. How can I achieve that?

Edit: As I mentioned in my comment below the command I'm trying to use is git or, more specific git-upload-pack and git-receive-pack and probably some others. I want to use them in different locations and occasions and don't want to bother setting up a git config on every machine I use it on or teach my IDE how to communicate with my NAS but rather have my NAS conforming standards. So i figured that all I need is to set the right $PATH

Edit II: what i did try so far was also inserting the export PATH=... as well as adding another echo (to verify they're run) to ~/.bash_profile, to /etc/profile and to ~/.bashrc. Apparently none of them are even executed when I run a non-interactive command like above. If I do ssh admin@nas all of them are executed, but that doesn't help

user2298896

Posted 2013-04-19T11:41:48.333

Reputation: 26

stick it in ~/.bash_profile – shorif2000 – 2013-04-19T14:35:35.880

i tried that along with adding another echo (to verify they're run) to ~/.bash_profile, to /etc/profile and to ~/.bashrc. Apparently none of them are even executed when I run a non-interactive command like above. If I do ssh admin@nas all of them are executed, but that doesn't help – user2298896 – 2013-04-19T14:43:18.357

How about ~/.bashrc? – Scott – 2013-04-19T20:11:04.580

As described in my previous comment, I tried that – user2298896 – 2013-04-20T12:33:59.067

log into root using su - – shorif2000 – 2013-04-22T09:37:43.837

I ended up creating Symlinks to the commands in question in /bin. That works for me. – user2298896 – 2013-04-23T16:57:35.280

Answers

1

If you are logged in as admin, ~/.bashrc is not used but ~/.profile is. So you can add this to .profile:

export PATH=\
/bin:\
/sbin:\
/opt/bin:\  #<--- HERE IT IS NOW
/usr/bin:\
/usr/sbin:\
/usr/bin/X11:\
/usr/local/bin

And PATH will be loaded like this when you login as admin. What I did on my nas is I added this to .bashrc, and changed .profile to have only 1 line:

source ~/.bashrc

So when you login as admin, you still get SH configured with .bashrc.

EDIT: I now understand what you want to do...

Just create symbolic links to those two binaries inside /usr/bin. For example:

cd /usr/bin && ln -s /opt/bin/git-upload-pack 

Cipi

Posted 2013-04-19T11:41:48.333

Reputation: 168

0

You can enter real address of command instead of command in ssh admin@nas command. Like below:

ssh admin@nas /opt/bin/command-name

Sepahrad Salour

Posted 2013-04-19T11:41:48.333

Reputation: 928

thanks for the reply, this does work but the command I'm trying to use is git or, more specific git-upload-pack and git-receive-pack and probably some others. I want to use them in different locations and occasions and don't want to bother setting up a git config on every machine I use it on or teach my IDE how to communicate with my NAS but rather have my NAS conforming standards. So i figured that all I need is to set the right $PATH – user2298896 – 2013-04-19T11:57:16.443