jayakumark has asked for the wisdom of the Perl Monks concerning the following question:

I had a script like below
SSHOpen("10.4.5.6", "admin"); sub SSHOpen { my $ip_address = shift @_; my $ssh_login = shift @_; print STDERR "Opening SSH Connection to $ip_address (as $ssh_login +)\n"; my $ssh_reader = new FileHandle; my $ssh_writer = new FileHandle; my $cmd; if (defined($ssh_login) && $ssh_login ne "") { $cmd = "ssh -l $ssh_login -o 'Batchmode yes' $ip_address 2>&1" +; } else { $cmd = "ssh -o 'Batchmode yes' $ip_address 2>&1"; } print STDERR "\tRunning <$cmd>\n"; my $pid = open2($ssh_reader, $ssh_writer, $cmd); if ($pid <= 0) { print STDERR "\tSSH could not connect!\n"; close($ssh_reader) if defined($ssh_reader); close($ssh_writer) if defined($ssh_writer); return 1; } print STDERR "Open 2 Successfull with pid $pid \n"; $ssh_reader->autoflush(); $ssh_writer->autoflush(); print STDERR "SSH Reader and Write Autoflush \n"; my %ssh = (); $ssh{'object_type'} = "SSH"; $ssh{'reader'} = $ssh_reader; $ssh{'writer'} = $ssh_writer; # lets test the connection by sending a blank command print STDERR "\tSuccessful End of SSHOpen Funtion\n"; return (0, \%ssh); }
I am getting error sh: ssh : not found.. but i can see /usr/local/bin (where ssh residess) in $ENV{PATH}. what may be the issue? Can somebody helpme on this. Thanks in advance.

Replies are listed 'Best First'.
Re: What is the path used by open2
by liverpole (Monsignor) on Jul 26, 2006 at 15:25 UTC
    Hi jayakumark,

    I ran your program myself, but didn't get any such error.

    What happens if you specify the full pathname of ssh ... /usr/local/bin/ssh?


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Thanks it is working..it was due to the reason that the script which i gave was running from another machine through remsh like "remsh machine2 -l admin /tmp/ssh.pl" so it was not able to find path environment variable. i just made it as "remsh machine2 -l admin /tmp/.env; /tmp/ssh.pl" it worked. thank you again
      I will try that and get back to u. Thanks for the quick reply