L
lovecreatesbeauty
I code ssh and telnet in script with Net::Telnet and Net::SSH:
erl.
It runs on Linux, but the ssh function of my script fails on Windows.
I then switch to Net::SSH::W32Perl and this change works on Linux
still. It issues `unimplemented getpwuid function error' on Windows. I
comment the getpwuid call in file `./Perl/site/lib/Net/SSH/Perl/
SSH2.pm' on Windows:
#my $home = $ENV{HOME} || (getpwuid($>))[7];
my $home = $ENV{HOME};
And set up an environment variable before run my script on Windows:
$ set home=%HOMEPATH%
$ perl rcmdw32.pl ssh "id" 192.168.50.50 root uit ""
[ hangs for whole night ]
$
My script hangs at Line 78, the Net::SSH:
erl->cmd() call and shows
no errors.
I manually interrupt it and see different errors accompanied with
`perl.exe application error' every time.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in keys at C:/Perl/site/lib/Net/SSH/
Perl/Channel.
pm line 140.
Can't coerce UNKNOWN to string in method_named at C:/Perl/site/lib/
Net/SSH/Perl/
SSH2.pm line 316.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in sassign at C:/Perl/lib/IO/Select.pm
line 78.
Use of freed value in iteration at C:/Perl/site/lib/Net/SSH/Perl/
Channel.pm line
140.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Terminating on signal SIG e
in an interactive session (see the docs for I<Net::SSH:
erl>),
and if so will issue a prompt, asking you to enter your password.
If the session is not interactive (if it's in batch mode), we
send a blank password to comply with the protocol, but `!@# INT(2)
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in shift at C:/Perl/site/lib/Net/SSH/
Perl/Packet.
pm line 154.
Attempt to free unreferenced scalar: SV 0x2458334, Perl interpreter:
0x276014 at
C:/Perl/site/lib/Net/SSH/Perl/Channel.pm line 139.
$
=====================================
| perl.exe - Application Error |
+-----------------------------------+
| "0x2809b0fb" instruction refers to|
| unwritable memory at "0x00000004" |
| |
| Press OK to exit, CANCEL to debug.|
| |
| [OK] [CANCEL] |
=====================================
(translation from dialog on Windows
of Chinese version )
Another problem is that I can install Net::SSH::W32Perl with CPAN
shell:
cpan> install Net::SSH::W32Perl
Net::SSH::W32Perl is up to date (0.05).
cpan>
But can't find and install this module through ActivePerl's ppm:
$ ppm install Net::SSH::W32Perl
Downloading ActiveState Package Repository packlist...not modified
Downloading ppm4.activestate.com packlist...not modified
No missing packages to install
$
Is this the cause of the problem? Can you please tell me how to find
tha install Net::SSH::W32Perl with ppm and any errors in my script.
Thank you for your time.
################################################################################
# Filename : rcmdw32.pl
# Synopsis : rcmdw32.pl <prot> <cmd> <host> <user> <pwd> <altpw>
# Author : (e-mail address removed)0m
# Date : May 30, 2008
################################################################################
#!/usr/bin/perl
#use warnings;
use strict;
use Net::Telnet();
use Net::SSH::W32Perl();
sub rcmd_usage;
sub rcmd;
exit rcmd(@ARGV);
################################################################################
# Function : rcmd <prot> <cmd> <host> <user> <pwd> <altpw>
# Description : Execute command on remote host. root privilege may be
required
# on some commands. This script is intended to automatically
# telnet to remote host or ssh to remote host in which neither
# /etc/hosts.equiv nor ~/.rhosts files may be available.
# Arguments : prot - telnet or ssh protocol to connect to host,
# cmd - command is to run on host,
# host - ip or name of host,
# user - user account to log on host,
# pwd - user's password,
# altpw - an alternative roots password on host if in need.
# Return : return 0 on success, otherwise non-zero.
################################################################################
sub rcmd
{
my ($prot, $cmd, $host, $user, $pwd, $altpw) = @_;
my ($narg, $npwd, $naltpw) = (scalar(@ARGV), length($pwd),
length($altpw));
my ($lg_prom, $pw_prom, $tmout) = ('/login[: ]*$/i',
'/password[: ]*$/i', 100);
my ($cnn, @aout);
if ($narg < 4 || $narg > 6){
rcmd_usage;
return 1;
}
# telnet with non-root, roots password required to execute other
command
# on remote host; or login directly with root on ssh connection.
if ($prot =~ /[Tt][Ee][Ll][Nn][Ee][Tt]/){
$cnn = new Net::Telnet(Timeout => $tmout);
$cnn->timeout($tmout);
$cnn->open($host);
$cnn->waitfor($lg_prom);
$cnn->print($user);
# The null string "" provided as password argument indicates no
# password is required from the user to login. don't check the
# password then.
if ($npwd != 0){
$cnn->waitfor($pw_prom);
$cnn->print($pwd);
}
$cnn->waitfor($cnn->prompt);
if ($naltpw != 0){
$cnn->print("su -");
$cnn->waitfor($pw_prom);
$cnn->print($altpw);
$cnn->waitfor($cnn->prompt);
}
} elsif ($prot =~ /[Ss][Ss][Hh]/){
$cnn = Net::SSH::W32Perl->new($host);
$cnn->login($user, $pwd);
} else {
rcmd_usage;
return 1;
}
@aout = $cnn->cmd($cmd); #LINE 78
print "@aout";
return 0;
}
################################################################################
# Function : rcmd_usage
# Description : print the usage of rcmd function
################################################################################
sub rcmd_usage
{
my $s = "Usage: rcmdw32.pl <prot> <cmd> <host> <user> <pwd>
<altpw>";
print "$s\n";
}
It runs on Linux, but the ssh function of my script fails on Windows.
I then switch to Net::SSH::W32Perl and this change works on Linux
still. It issues `unimplemented getpwuid function error' on Windows. I
comment the getpwuid call in file `./Perl/site/lib/Net/SSH/Perl/
SSH2.pm' on Windows:
#my $home = $ENV{HOME} || (getpwuid($>))[7];
my $home = $ENV{HOME};
And set up an environment variable before run my script on Windows:
$ set home=%HOMEPATH%
$ perl rcmdw32.pl ssh "id" 192.168.50.50 root uit ""
[ hangs for whole night ]
$
My script hangs at Line 78, the Net::SSH:
no errors.
I manually interrupt it and see different errors accompanied with
`perl.exe application error' every time.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in keys at C:/Perl/site/lib/Net/SSH/
Perl/Channel.
pm line 140.
Can't coerce UNKNOWN to string in method_named at C:/Perl/site/lib/
Net/SSH/Perl/
SSH2.pm line 316.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in sassign at C:/Perl/lib/IO/Select.pm
line 78.
Use of freed value in iteration at C:/Perl/site/lib/Net/SSH/Perl/
Channel.pm line
140.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Terminating on signal SIG e
in an interactive session (see the docs for I<Net::SSH:
and if so will issue a prompt, asking you to enter your password.
If the session is not interactive (if it's in batch mode), we
send a blank password to comply with the protocol, but `!@# INT(2)
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in shift at C:/Perl/site/lib/Net/SSH/
Perl/Packet.
pm line 154.
Attempt to free unreferenced scalar: SV 0x2458334, Perl interpreter:
0x276014 at
C:/Perl/site/lib/Net/SSH/Perl/Channel.pm line 139.
$
=====================================
| perl.exe - Application Error |
+-----------------------------------+
| "0x2809b0fb" instruction refers to|
| unwritable memory at "0x00000004" |
| |
| Press OK to exit, CANCEL to debug.|
| |
| [OK] [CANCEL] |
=====================================
(translation from dialog on Windows
of Chinese version )
Another problem is that I can install Net::SSH::W32Perl with CPAN
shell:
cpan> install Net::SSH::W32Perl
Net::SSH::W32Perl is up to date (0.05).
cpan>
But can't find and install this module through ActivePerl's ppm:
$ ppm install Net::SSH::W32Perl
Downloading ActiveState Package Repository packlist...not modified
Downloading ppm4.activestate.com packlist...not modified
No missing packages to install
$
Is this the cause of the problem? Can you please tell me how to find
tha install Net::SSH::W32Perl with ppm and any errors in my script.
Thank you for your time.
################################################################################
# Filename : rcmdw32.pl
# Synopsis : rcmdw32.pl <prot> <cmd> <host> <user> <pwd> <altpw>
# Author : (e-mail address removed)0m
# Date : May 30, 2008
################################################################################
#!/usr/bin/perl
#use warnings;
use strict;
use Net::Telnet();
use Net::SSH::W32Perl();
sub rcmd_usage;
sub rcmd;
exit rcmd(@ARGV);
################################################################################
# Function : rcmd <prot> <cmd> <host> <user> <pwd> <altpw>
# Description : Execute command on remote host. root privilege may be
required
# on some commands. This script is intended to automatically
# telnet to remote host or ssh to remote host in which neither
# /etc/hosts.equiv nor ~/.rhosts files may be available.
# Arguments : prot - telnet or ssh protocol to connect to host,
# cmd - command is to run on host,
# host - ip or name of host,
# user - user account to log on host,
# pwd - user's password,
# altpw - an alternative roots password on host if in need.
# Return : return 0 on success, otherwise non-zero.
################################################################################
sub rcmd
{
my ($prot, $cmd, $host, $user, $pwd, $altpw) = @_;
my ($narg, $npwd, $naltpw) = (scalar(@ARGV), length($pwd),
length($altpw));
my ($lg_prom, $pw_prom, $tmout) = ('/login[: ]*$/i',
'/password[: ]*$/i', 100);
my ($cnn, @aout);
if ($narg < 4 || $narg > 6){
rcmd_usage;
return 1;
}
# telnet with non-root, roots password required to execute other
command
# on remote host; or login directly with root on ssh connection.
if ($prot =~ /[Tt][Ee][Ll][Nn][Ee][Tt]/){
$cnn = new Net::Telnet(Timeout => $tmout);
$cnn->timeout($tmout);
$cnn->open($host);
$cnn->waitfor($lg_prom);
$cnn->print($user);
# The null string "" provided as password argument indicates no
# password is required from the user to login. don't check the
# password then.
if ($npwd != 0){
$cnn->waitfor($pw_prom);
$cnn->print($pwd);
}
$cnn->waitfor($cnn->prompt);
if ($naltpw != 0){
$cnn->print("su -");
$cnn->waitfor($pw_prom);
$cnn->print($altpw);
$cnn->waitfor($cnn->prompt);
}
} elsif ($prot =~ /[Ss][Ss][Hh]/){
$cnn = Net::SSH::W32Perl->new($host);
$cnn->login($user, $pwd);
} else {
rcmd_usage;
return 1;
}
@aout = $cnn->cmd($cmd); #LINE 78
print "@aout";
return 0;
}
################################################################################
# Function : rcmd_usage
# Description : print the usage of rcmd function
################################################################################
sub rcmd_usage
{
my $s = "Usage: rcmdw32.pl <prot> <cmd> <host> <user> <pwd>
<altpw>";
print "$s\n";
}