howruaz9
asked on
How to use module Net::SSH::Perl?
I tried to use Net::SSH::Perl as below, but got error message. (I could manually login this server using putty)
Is there anyone know how to do it.
Thanks very much!
Is there anyone know how to do it.
Thanks very much!
use Net::SSH::Perl;
$host="testserver";
$user="bnfjghy";
$pass="sdhj3$%ED";
$cmd="ls -l";
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "$stdout\n";
my($stdout, $stderr, $exit) = $ssh->cmd(exit);
ss.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Adam314. I will install Net::SSH::W32Perl and try on it.
ASKER
ppm install --location=http://www.soulcage.net/ppds Net::SSH::W32Perl
ASKER
I have tried many different ways to install. But it didn't work.
ASKER
Did you ever try:
set HOME=value_can_be_anything
just for the heck of it?
set HOME=value_can_be_anything
just for the heck of it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you nemws1, but It still didn't work after set home.
The error message is below
Can't set socket non-blocking: Bad file descriptor at C:/Perl/site/lib/Net/SSH/P
erl.pm line 216.
home.bmp
The error message is below
Can't set socket non-blocking: Bad file descriptor at C:/Perl/site/lib/Net/SSH/P
erl.pm line 216.
home.bmp
ASKER
Thanks very much Adam314.
I tried to add Soulcage in Repositories. after it done, the number of pkgs is 0.
Please see attached file.
Thanks you so much anyway.
1.bmp
I tried to add Soulcage in Repositories. after it done, the number of pkgs is 0.
Please see attached file.
Thanks you so much anyway.
1.bmp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much Adam314.
I followed your instruction to install Net::SSH::W32Perl. The below is result. Please help me check where I did wrong. Thank you again.
5.bmp
I followed your instruction to install Net::SSH::W32Perl. The below is result. Please help me check where I did wrong. Thank you again.
use Net::SSH::Perl;
use Net::SSH::W32Perl;
$host="testserver";
$user="bnfjghy";
$pass="sdhj3$%ED";
$cmd="ls -l";
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "$stdout\n";
4.bmp5.bmp
You need to tell your program to use Net::SSH::W32Perl instead of Net::SSH::Perl.
Remove this line:
use Net::SSH::Perl;
Change this line:
my $ssh = Net::SSH::Perl->new($host) ;
To this:
my $ssh = Net::SSH::W32Perl->new($ho st);
Remove this line:
use Net::SSH::Perl;
Change this line:
my $ssh = Net::SSH::Perl->new($host)
To this:
my $ssh = Net::SSH::W32Perl->new($ho
ASKER
I have changed as you said. The result is below.
7.bmp
7.bmp
I hope it isn't a case problem. Your 'w' in 'w32' is lowercase. Windows doesn't care, but Perl might. Change the 'w' to uppercase and try again.
Yes, case matters. You need to have the W in upper case.
ASKER
Thanks very much nemws1 and Adam314.
I will try it tomorrow in company because I can't test at home.
I really appreciate your kind help!
I will try it tomorrow in company because I can't test at home.
I really appreciate your kind help!
ASKER
I have changed the W in upper case. below is what I got.
Is there anyone know what it mean?
Thanks
Is there anyone know what it mean?
Thanks
ASKER
You still need the HOME environment variable set to your home directory:
set HOME=c:\Documents and Settings\howruaz9
set HOME=c:\Documents and Settings\howruaz9
ASKER
After set Home, it get much better, but there is still some error message and stop at step 3 .....
#system("set HOME=C:\IS");
use Net::SSH::W32Perl;
$host="testserver";
$user="bnfjghy";
$pass="sdhj3$%ED";
$cmd="ls -l";
my $ssh = Net::SSH::W32Perl->new($host);
print "\ndone 1\n";
$ssh->login($user, $pass);
print "\ndone 2\n";
$ssh->session_id;
print "\ndone 3\n";
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "\ndone 4\n";
print "$stdout\n";
my($stdout, $stderr, $exit) = $ssh->cmd("exit");
print "\ndone 5\n";
done-3.bmp
Do you have Math::BigInt installed?
ASKER
Yes, I have Math::BigInt.
33.bmp
33.bmp
The messages you got are not errors, they are warnings. The Math::BigInt module has several sub-modules it uses for various things. If those modules aren't available, it can do the stuff itself, but is slower (sometimes much slower). The warnings you got are telling you that it couldn't use the faster sub-module, so it's using a slower pure-perl module instead.
To address, try a re-install of these:
Math::BigInt
Math::BigInt::GMP
Math::BigInt::Pari
Math::BigInt::BitVector
What is the error after step 3?
To address, try a re-install of these:
Math::BigInt
Math::BigInt::GMP
Math::BigInt::Pari
Math::BigInt::BitVector
What is the error after step 3?
ASKER
After step 3, waiting looooong time, No any other message.
I will re-install the modules you mentioned.
Thank you very much Adam314
I will re-install the modules you mentioned.
Thank you very much Adam314
ASKER
I have re-installed Math::BigInt, Math::BigInt::GMP, Math::BigInt::Pari. But can't find Math::BigInt::BitVector.
4.bmp
4.bmp
Try removing the "ls -l" command, just log in then exit.
ASKER
Sure. I will tell you the result on Monday. Have a nice weekend.
ASKER
Below is result. Stop at step 3, there is no any error message. WHY????????????
#system("set HOME=C:\IS");
use Net::SSH::W32Perl;
$host="testserver";
$user="bnfjghy";
$pass="sdhj3$%ED";
$cmd="ls -l";
my $ssh = Net::SSH::W32Perl->new($host);
print "\ndone 1\n";
$ssh->login($user, $pass);
print "\ndone 2\n";
$ssh->session_id;
print "\ndone 3\n";
# my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
# print "\ndone 4\n";
# print "$stdout\n";
my($stdout, $stderr, $exit) = $ssh->cmd("exit");
print "\ndone 5\n";
222.bmp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much Adam314.
Option 3 and 4 worked; Option 1 and 2 didn't work;.
please see attached file
it executed my($stdout, $stderr, $exit) = $ssh->cmd("ls -l > /dev/null 2> /dev/null ");
but didn't execute print "$stdout\n";
How can I get result after execute a command?
option.bmp
Option 3 and 4 worked; Option 1 and 2 didn't work;.
please see attached file
it executed my($stdout, $stderr, $exit) = $ssh->cmd("ls -l > /dev/null 2> /dev/null ");
but didn't execute print "$stdout\n";
How can I get result after execute a command?
option.bmp
It appears there is a bug that causes it to hang when there is output on STDERR. Try these. If they work, you should have $stdout. The second will also giver your STDERR in $stdout.
##### Option 6
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l 2> /dev/null");
print "done option 6\n";
print " stdout=$stdout\n";
print " stderr=$stderr\n";
print " exit=$exit\n";
##### Option 7
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l 2> \&1");
print "done option 7\n";
print " stdout=$stdout\n";
print " stderr=$stderr\n";
print " exit=$exit\n";
ASKER
Sorry, Adam314, Option 6/7 didn't work. script stop at step 3. There is no any error message.
Maybe the problem is with getting any output. How about this:
##### Option 8
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l > /dev/null 2> /dev/null");
print "done option 8\n";
print " stdout=$stdout\n";
print " stderr=$stderr\n";
print " exit=$exit\n";
##### Option 9 (change output file name if needed)
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l > /tmp/test1.txt 2> /dev/null");
print "done option 9\n";
print " stdout=$stdout\n";
print " stderr=$stderr\n";
print " exit=$exit\n";
ASKER
I have tried option 8 and 9. It didn't work.
More confusion is below command didn't work SOMETIME, I used Putty manually login test server, there was no problem
my($stdout, $stderr, $exit) = $ssh->cmd("exit > /dev/null 2> /dev/null");
I also found when execute this script, it create a new directory .ssh. What does this mean?
Thanks so much Adam314 for your time and patien.
1.bmp
More confusion is below command didn't work SOMETIME, I used Putty manually login test server, there was no problem
my($stdout, $stderr, $exit) = $ssh->cmd("exit > /dev/null 2> /dev/null");
I also found when execute this script, it create a new directory .ssh. What does this mean?
Thanks so much Adam314 for your time and patien.
1.bmp
Don't you already have an .ssh directory in your home directory? Do you have have the HOME environment variable pointing to your home directory, probably something like C:\Documents and Settings\<username>?
ASKER
This .ssh directory is the only one on hard driver.
For environment variable, please see following file.
eee.bmp
For environment variable, please see following file.
eee.bmp
What version of perl are you using?
ASKER
This is perl, v5.10.0 built for MSWin32-x86-multi-thread
Thanks
Thanks
ASKER
Adam314 and nemws1, I really appreciate your help!
ASKER