Ted Zeng wrote:
> Hi,
> 
> Why the system behaves differently when I ssh to a machine
> from Terminal than when I ssh to the same machine by Perl's SSH module?
>
> Here is the problem:
> I added a tool to /usr/local/bin. I updated the profile file.
> Now if I ssh to the machine, I could use "which tool" to find it.
> 
> But when I try to do the same in Perl, the reply is
> "no tool in /usr/bin /bin /usr/sbin /sbin"
> 
> ted zeng
> Adobe Systems
> 
> 

The difficult part is that the answer is really "just because" :-). When
you use the 'ssh' from the terminal you are using the local ssh client.
That client establishes a connection to a remote ssh server and tells
that server that it wants to run a command, that command is to init a
shell and then interact.  So when you send your 'which' command you are
interacting with the remote shell over the ssh "tunnel". But when you
use Net::SSH::Perl (which I am assuming is the module you are using) you
are establishing a connection to a remote SSH session, but the
command(s) you send are being exec'd directly (presumably by /bin/sh)
which may or may not have loaded the same environment as the normal user
shell (for instance, skipping any .bashrc/.bash_profile, etc.). I
believe (though haven't tested) that the same would occur if you
provided a command to the local ssh client instead of requesting an
interactive shell.

Net::SSH provides a wrapper around the local 'ssh' command but I have
not used it. I tested it once quite a while ago and preferred
Net::SSH::Perl *for my purposes*.

HTH,

http://danconia.org

Reply via email to