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

while iam trying with simple code like this
use Net::SSH::W32Perl; my $ssh = Net::SSH::W32Perl->new($host,use_pty => 0,); $ssh->login($user, $pass); my $Command="ls -lrt"; my($stdout, $stderr, $exit) = $ssh->cmd($Command); print "$stdout";
yes it is wroking fine,giving the out put also
but iam using in TK ,as function it is giving errors
sub ConnectSSH { print LOG " [FunctionName][ConnectSSH] \n"; my $ClearCaseSSHObject = Net::SSH::W32Perl->new($host,use_pty => +0,debug=>1); if($ClearCaseSSHObject) { if(!$ClearCaseSSHObject->login('$user','$password') ) { print LOG " Unable to connect SSH \n"; &ErrorNotification(ERR_LOGIN_TITLE,ERR_LOGIN_MSG); $MainScreenObject -> Unbusy( -recurse => '1' ) +; return(0); } else { print LOG "connected Sucesfully"; } } else { print LOG " Unable to connect network \n"; &ErrorNotification("ERR_CON_TITLE","ERR_CON_MSG"); } #For retrieving SSHobject decalring globally $ClearCaseSSHObjectRef = $ClearCaseSSHObject; return($ClearCaseSSHObjectRef); }

indamaaaf31786: Reading configuration data /.ssh/config indamaaaf31786: Reading configuration data /etc/ssh_config indamaaaf31786: Connecting to host, port 22. indamaaaf31786: Socket created, turning on blocking... indamaaaf31786: Remote protocol version 2.0, remote software version OpenSSH_3.7.1p2-pwexp26 "makerandom" is not exported by the Crypt::Random module at E:/perl/site/lib/Crypt/Random/Generator.pm line 12 "makerandom_itv" is not exported by the Crypt::Random module at E:/perl/site/lib/Crypt/Random/Generator.pm line 12 "makerandom_octet" is not exported by the Crypt::Random module at E:/prl/site/lib/Crypt/Random/Generator.pm line 12 Tk::Error: Can't continue after import errors at E:/perl/site/lib/Crypt/Random/Generator.pm line 12 BEGIN failed--compi +lation aborted at E:/perl/site/lib/Crypt/Random/Generator.pm line 12, <GEN2> line 1. Compilation failed in require at E:/perl/site/lib/Crypt/Random.pm line 18, <GEN2> line 1. BEGIN failed- +-compilation aborted at E:/perl/site/lib/Crypt/Random.pm line 18, <GEN2> line 1. Compilation f +ailed in require at E:/perl/site/lib/Crypt/DH.pm line 6, <GEN2> line 1. BEGIN failed--comp +ilation aborted at E:/perl/site/lib/Crypt/DH.pm line 6, <GEN2> line 1. Compilation failed + in require at E:/perl/site/lib/Net/SSH/Perl/Kex/DH1.pm line 13, <GEN2> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex/DH1.pm line 13, <GEN2> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/Kex.pm line 6, <GEN2> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex.pm line 6, <GEN2> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/SSH2.pm line 6, <GEN2> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/SSH2.pm line 6, <GEN2> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/W32Perl/SSH2.pm line 7, <GEN2> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/W32Perl/SSH2.pm line 7, <GEN2> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl.pm line 55, <GEN2> line 1. Crypt::Random +::BEGIN at E:/perl/site/lib/Crypt/Random.pm line 18 Crypt::DH::BEGIN at E:/perl/site/lib/Crypt/DH.pm line 6 Net::SSH::Perl::Kex::DH1::BEGIN at E:/perl/site/lib/Net/SSH/Perl/Kex/DH1.pm line 13 Net::SSH::Perl::Kex:: +BEGIN at E:/perl/site/lib/Net/SSH/Perl/Kex.pm line 6 Net::SSH::Perl::SSH2::BEGI +N at E:/perl/site/lib/Net/SSH/Perl/SSH2.pm line 6

Edited by planetscape - added code tags around program output

( keep:1 edit:10 reap:0 )

2006-07-11 Retitled by planetscape, as per Monastery guidelines

( keep:3 edit:9 reap:0 )

Original title: 'SSH not wroking with TK'

Replies are listed 'Best First'.
Re: SSH not working with TK
by zentara (Cardinal) on Jul 10, 2006 at 17:02 UTC
    I don't see your comparison between your working snippet, and your failing sub. The failing sub dosn't resemble the working snippet at all. This snippet works on linux, you might try to substitute your working snippet and see if it goes.
    #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Tk; my $mw = MainWindow->new; my $text = $mw->Text(); $text->pack; $text->insert('end',"Net::SSH::Perl Test\n"); $mw->Button( -text => "SSH", -command => \&do_ssh )->pack; $mw->Button( -text => "Exit", -command => sub{exit} )->pack; MainLoop; sub do_ssh{ my $user = "z"; my $password = "ztest"; my @hosts = qw(localhost); foreach my $host (@hosts){ my $cmd = "/usr/bin/uptime"; my $ssh = Net::SSH::Perl->new( $host, port => 22 , protocol => 2, # debug => 1, ); $ssh->login($user,$password); my($out) = $ssh->cmd($cmd); my ($time,$uptime) = (split /\s+/,$out)[1,3]; chop $uptime; $text->insert('end', "$out\n"); $text->insert('end', "$host has been up $uptime\n"); } }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      same function telnet is wroking fine in TK programs then why SSH not wroking?
      sub ConnectTelnet { print LOG " [FunctionName][ConnectTelnet] \n"; my $TelnetObject = new Net::Telnet(Timeout => 100,Errmode => ' +return'); if($TelnetObject->open("$HostName")) { if(!$TelnetObject->login($TelnetUserId,$UnixPassword) ) { print LOG " Unable to connect telnet \n"; &ErrorNotification(ERR_LOGIN_TITLE,ERR_LOGIN_MSG); $MainScreenObject -> Unbusy( -recurse => '1' ); return(0); } else { print LOG "connected Sucesfully"; } } else { print LOG " Unable to connect network \n"; &ErrorNotification("ERR_CON_TITLE","ERR_CON_MSG"); } #For retrieving telnetobject decalring globally $TelnetObjectRef = $TelnetObject; return($TelnetObject); }

        is Net::SSH::W32Perl wroking with Tk functions?
        bcoz i have given code Net::SSH::W32Perl it is wroking if
        I use just Tk in That code (like This use Tk;).it is giving errors like below

        indamaaaf31786: Reading configuration data /.ssh/config indamaaaf31786: Reading configuration data /etc/ssh_config indamaaaf31786: Connecting to host, port 22. indamaaaf31786: Socket created, turning on blocking... indamaaaf31786: Remote protocol version 2.0, remote software version O +penSSH_3.7.1p2-pwexp26 "makerandom" is not exported by the Crypt::Random module at E:/perl/si +te/lib/Crypt/Random/Generator.pm line 12 "makerandom_itv" is not exported by the Crypt::Random module at E:/per +l/site/lib/Crypt/Random/Generator.pm line 12 "makerandom_octet" is not exported by the Crypt::Random module at E:/p +erl/site/lib/Crypt/Random/Generator.pm line 12 Can't continue after import errors at E:/perl/site/lib/Crypt/Random/Ge +nerator.pm line 12 BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/Random/Gen +erator.pm line 12, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Crypt/Random.pm line + 18, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/Random.pm +line 18, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Crypt/DH.pm line 6, +<GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/DH.pm line + 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/Kex/DH1 +.pm line 13, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex +/DH1.pm line 13, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/Kex.pm +line 6, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex +.pm line 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/SSH2.pm + line 6, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/SSH +2.pm line 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/W32Perl/SSH2 +.pm line 7, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/W32Perl/ +SSH2.pm line 7, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl.pm line + 55, <GEN0> line 1.

        20060711 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips