Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Path issue when executing commands remotely

3 views
Skip to first unread message

Mark

unread,
Jul 1, 2009, 3:53:11 AM7/1/09
to

When I try and execute a command which sits in /usr/sbin on a remote
machine, for some reason it cannot find it:

ssh user1@<remote-hosts> ifconfig -a
sh: ifconfig: not found

But when I do

ssh user1@<remote-hosts> ls

This works!

When I log on to the remote machine as that user1 and run ifconfig -a
it works, and /usr/sbin is in the path. I have tried setting it in /
etc/profile and .profile and local.profile on the remote users
machine. However it still does not help.

Does anyone know why? and where I should set the path on the remote
machine to run commands in /usr/sbin?

Thanks in advance


hume.sp...@bofh.ca

unread,
Jul 1, 2009, 7:24:54 AM7/1/09
to
Mark <cconn...@lycos.com> wrote:
> Does anyone know why? and where I should set the path on the remote
> machine to run commands in /usr/sbin?

What shell is your user configured with? For bash or ksh, $HOME/.profile
usually does the trick. For csh or tcsh, look at $HOME/.cshrc and
$HOME/.tcshrc.

Keep in mind that the syntax for setting the PATH variable differs between
the shells, too.

--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/

ThanksButNo

unread,
Jul 1, 2009, 11:27:41 AM7/1/09
to

Of course, when you connect remotely you get a default
PATH which for non-root users doesn't include /usr/sbin.

I think that connecting remotely ignores running the
user's ".profile" etc. So you'll be stuck with the
default PATH.

You can confirm this as follows:

ssh user1@<remote-hosts> 'echo $PATH'

(be sure to use single quotes (') not double (") so that
the dollar-var won't be expanded until it gets to the
remote host)

I can think of three solutions:

The obvious one, use the full path:

ssh user1@<remote-hosts> /usr/sbin/ifconfig -a

Probably less obvious, on the remote host, edit the
file, /etc/default/login.

Look for the line that reads "PATH=/usr/bin...{etc}"
Add "/usr/sbin" to that line. That will make every
normal user have "/usr/sbin" added to their default
PATH.

Finally, if you really want the remote command to use
the remote user's ".profile", thus getting whatever
PATH is set up, without changing the default, and
without using the full path, you can pass a remote
shell *interactive* command. That forces a read of
the user's .profile etc.

Try these two options:

ssh user1@<remote-hosts> 'echo $PATH'
ssh user1@<remote-hosts> 'sh -i echo $PATH'

See what the difference is.

I believe you're probably better off with the first
option, using the full path, but that's my opinion.

\:-\

Canuck57

unread,
Jul 1, 2009, 11:31:56 AM7/1/09
to

<hume.sp...@bofh.ca> wrote in message
news:h2fh26$9q6$1...@Kil-nws-1.UCIS.Dal.Ca...

> Mark <cconn...@lycos.com> wrote:
>> Does anyone know why? and where I should set the path on the remote
>> machine to run commands in /usr/sbin?
>
> What shell is your user configured with? For bash or ksh, $HOME/.profile
> usually does the trick. For csh or tcsh, look at $HOME/.cshrc and
> $HOME/.tcshrc.
>
> Keep in mind that the syntax for setting the PATH variable differs between
> the shells, too.

Many remote commands do not run the profiles.

It is why many a skilled scripters and command line people specify the full
path:

/usr/bin/find .....

That way it remove ambiguity. Especially if there are multiple versions of
the same executable in the path.


0 new messages