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); }