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
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/
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.
\:-\
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.