Click here to get back home

Remote.pm (File::Remote) problem

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Remote.pm (File::Remote) problem Dayton Jones 02-28-2006
Get Chitika Premium
Posted by A. Sinan Unur on March 1, 2006, 11:52 am
Please log in for more thread options



Dayton, *please* do not top-post.

> A. Sinan Unur wrote:
>>
>>
>>>A. Sinan Unur wrote:
>>>
>>>>
>>>>
>>>>> I've got a very simple script (see below) that uses the
>>>>> File::Remote module. I've set up the script to use ssh/scp
>>>>> and there is no problem for the user to ssh to the hosts -
>>>>> but the script fails with a "permission denied" error on the
>>>>>> copy command.
>>>>>
>>>>>-- begin script
>>>>>
>>>>>#!/usr/bin/perl
>>>>
>>>>
>>>>use strict;
>>>>use warnings;
>>>>
>>>>missing.
>>>>
>>>>
>>>>>use File::Remote qw(:replace);
>>>>>
>>>>>setrsh('/usr/bin/ssh');
>>>>>serrcp('/usr/bin/scp');
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> ...
>>
>>
>>>I added the strict/warnings but had the same result -- with no extra
>>>information.
>>
>>
>> Well, did you fix the typo above?
>>
>> I don't have File-Remote installed, by I doubt serrcp is correct.
>
> Yes, I noticed that when reading your original response -- changed it
> to "setrcp="

Well, apologoies, I misdiagnosed the problem. I looked at the source
code of File::Remote, and the problem simply is that /dev/null has a
different name on Windows, i.e. NUL.

The dirty fix would involve replacing File::Remote::_system.

You could also just go in and edit out the 1 > /dev/null out of the
backticked string. But then, you'd be modifiying a module, and it might
get overwritten when you upgrade to a new version etc.

#!/usr/bin/perl

use strict;
use warnings;

use File::Remote qw(:replace);
use File::Spec::Functions qw( canonpath );

setrsh(canonpath 'C:/opt/cygwin/bin/ssh.exe');
setrcp(canonpath 'C:/opt/cygwin/bin/scp.exe');
settmp(canonpath $ENV);

{
no warnings 'redefine';
*File::Remote::_system = sub {
my($self, @cmd) = File::Remote::_self_or_default(@_);

# return "Broken pipe" if cmd invalid
# chomp(my $return = `@cmd 2>&1 1>/dev/null || echo 32`);
chomp(my $return = `@cmd 2>&1 1>NUL || echo 32`);
File::Remote::_debug("_system(@cmd) = $return");

if ($return) {
# if echo'ed an int (internal tests), use it,
# else use "Permission denied" (13)
$return =~ m/^(\d+)$/;
$! = $1 || 13;
return undef;
}
return 1;
};
}

copy('localfile', 'remotefile')
or die "$\@ = $@\n$! = $!\n";

__END__

Sinan

--
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


Posted by harryfmudd [AT] comcast [DOT] on March 2, 2006, 8:04 am
Please log in for more thread options


A. Sinan Unur wrote:
>
> Well, apologoies, I misdiagnosed the problem. I looked at the source
> code of File::Remote, and the problem simply is that /dev/null has a
> different name on Windows, i.e. NUL.

Yeah, Perl is eminently portable - until someone sticks in an
OS-specific construct. Maybe this is the Unix programmers' revenge for
all those stupid question marks in web pages made by windows users.

>
> The dirty fix would involve replacing File::Remote::_system.
>
> You could also just go in and edit out the 1 > /dev/null out of the
> backticked string. But then, you'd be modifiying a module, and it might
> get overwritten when you upgrade to a new version etc.

Another alternative is to contact the creater of the module. If he's
willing to have his module dependent on File::Spec, he can get the
correct device name from File::Spec->devnull(), and not have to worry
about what to call the null device. The File::Spec solution also covers
VMS, which calls it NLA0:.

Tom Wyant

Posted by Dayton Jones on March 2, 2006, 10:51 am
Please log in for more thread options


A. Sinan Unur wrote:
>
> Dayton, *please* do not top-post.
>
>
>>A. Sinan Unur wrote:
>>
>>>
>>>
>>>
>>>>A. Sinan Unur wrote:
>>>>
>>>>
>>>>>
>>>>>
>>>>>
>>>>>>I've got a very simple script (see below) that uses the
>>>>>>File::Remote module. I've set up the script to use ssh/scp
>>>>>>and there is no problem for the user to ssh to the hosts -
>>>>>>but the script fails with a "permission denied" error on the
>>>>>>
>>>>>>>copy command.
>>>>>>
>>>>>>-- begin script
>>>>>>
>>>>>>#!/usr/bin/perl
>>>>>
>>>>>
>>>>>use strict;
>>>>>use warnings;
>>>>>
>>>>>missing.
>>>>>
>>>>>
>>>>>
>>>>>>use File::Remote qw(:replace);
>>>>>>
>>>>>>setrsh('/usr/bin/ssh');
>>>>>>serrcp('/usr/bin/scp');
>>>
>>>^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>...
>>>
>>>
>>>
>>>>I added the strict/warnings but had the same result -- with no extra
>>>>information.
>>>
>>>
>>>Well, did you fix the typo above?
>>>
>>>I don't have File-Remote installed, by I doubt serrcp is correct.
>>
>>Yes, I noticed that when reading your original response -- changed it
>>to "setrcp="
>
>
> Well, apologoies, I misdiagnosed the problem. I looked at the source
> code of File::Remote, and the problem simply is that /dev/null has a
> different name on Windows, i.e. NUL.
>
> The dirty fix would involve replacing File::Remote::_system.
>
> You could also just go in and edit out the 1 > /dev/null out of the
> backticked string. But then, you'd be modifiying a module, and it might
> get overwritten when you upgrade to a new version etc.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use File::Remote qw(:replace);
> use File::Spec::Functions qw( canonpath );
>
> setrsh(canonpath 'C:/opt/cygwin/bin/ssh.exe');
> setrcp(canonpath 'C:/opt/cygwin/bin/scp.exe');
> settmp(canonpath $ENV);
>
> {
> no warnings 'redefine';
> *File::Remote::_system = sub {
> my($self, @cmd) = File::Remote::_self_or_default(@_);
>
> # return "Broken pipe" if cmd invalid
> # chomp(my $return = `@cmd 2>&1 1>/dev/null || echo 32`);
> chomp(my $return = `@cmd 2>&1 1>NUL || echo 32`);
> File::Remote::_debug("_system(@cmd) = $return");
>
> if ($return) {
> # if echo'ed an int (internal tests), use it,
> # else use "Permission denied" (13)
> $return =~ m/^(\d+)$/;
> $! = $1 || 13;
> return undef;
> }
> return 1;
> };
> }
>
> copy('localfile', 'remotefile')
> or die "$\@ = $@\n$! = $!\n";
>
> __END__
>
> Sinan
>

OK, now I'm confused -- I'm not running on a windows platform so the
/dev/null reference is correct. I'm running RedHat EL3 and EL4 -- my
apologies for not specifying that earlier.

Posted by A. Sinan Unur on March 2, 2006, 11:06 am
Please log in for more thread options


og@comcast.com:

> A. Sinan Unur wrote:
...

>>>>>A. Sinan Unur wrote:
>>>>>
>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I've got a very simple script (see below) that uses the
>>>>>>>File::Remote module. I've set up the script to use ssh/scp
>>>>>>>and there is no problem for the user to ssh to the hosts -
>>>>>>>but the script fails with a "permission denied" error on the
>>>>>>>
>>>>>>>>copy command.

...

>>>>>>>use File::Remote qw(:replace);
>>>>>>>
>>>>>>>setrsh('/usr/bin/ssh');
>>>>>>>serrcp('/usr/bin/scp');
>>>>
>>>>^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>...
>>>>

...

>> Well, apologoies, I misdiagnosed the problem. I looked at the source
>> code of File::Remote, and the problem simply is that /dev/null has a
>> different name on Windows, i.e. NUL.

...

> OK, now I'm confused -- I'm not running on a windows platform so the
> /dev/null reference is correct. I'm running RedHat EL3 and EL4 -- my
> apologies for not specifying that earlier.

Please trim your replies a bit. I don't think I did a good job after so
many repeated full quotes.

Upon looking at File::Remote again, I noticed that there is another
potential bug in File::Remote::_system:

sub _system {
my($self, @cmd) = _self_or_default(@_);

# return "Broken pipe" if cmd invalid
chomp(my $return = `@cmd 2>&1 1>/dev/null || echo 32`);
_debug("_system(@cmd) = $return");

if ($return) {
# if echo'ed an int (internal tests), use it,
# else use "Permission denied" (13)
$return =~ m/^(\d+)$/;
$! = $1 || 13;

Notice how $! is set without checking if the match above succeeded? That
might cause this routine to report an error when there was none if $1
had been set earlier.

Are you sure the file was not copied?

Another idea is to temporarily enable debugging by setting $DEBUG = 1
aorund line 114 of the module:

# Simple debugging function
my $DEBUG = 1;
sub _debug { warn "debug: ", @_ if $DEBUG };

See what you get in the actual trace.


Sinan
--
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


Posted by Dayton Jones on March 2, 2006, 8:12 pm
Please log in for more thread options


A. Sinan Unur wrote:

> Upon looking at File::Remote again, I noticed that there is another
> potential bug in File::Remote::_system:
>
> sub _system {
> my($self, @cmd) = _self_or_default(@_);
>
> # return "Broken pipe" if cmd invalid
> chomp(my $return = `@cmd 2>&1 1>/dev/null || echo 32`);
> _debug("_system(@cmd) = $return");
>
> if ($return) {
> # if echo'ed an int (internal tests), use it,
> # else use "Permission denied" (13)
> $return =~ m/^(\d+)$/;
> $! = $1 || 13;
>
> Notice how $! is set without checking if the match above succeeded? That
> might cause this routine to report an error when there was none if $1
> had been set earlier.
>
> Are you sure the file was not copied?
>
> Another idea is to temporarily enable debugging by setting $DEBUG = 1
> aorund line 114 of the module:
>
> # Simple debugging function
> my $DEBUG = 1;
> sub _debug { warn "debug: ", @_ if $DEBUG };
>
> See what you get in the actual trace.
>
>
> Sinan



Well, enabling debug basically looks like it's pointing the finger at
ssh/scp :

debug: copy -- system(File::Remote=HASH(0x9bd55b4)->setrcp,
host1:/tmp/file, host1:/tmp/file2) at
/usr/lib/perl5/site_perl/5.8.5/File/Remote.pm line 115.
debug: _system(/usr/bin/scp host1:/tmp/file host1:/tmp/file2) = Host key
verification failed.
lost connection
32 at /usr/lib/perl5/site_perl/5.8.5/File/Remote.pm line 115.
host1 :: Permission denied


So even though, as that user I can ssh/scp to host1 with no problems,
the module can't pass the host verification stage...

Similar ThreadsPosted
Remote.pm (File::Remote) error handling question January 29, 2007, 12:57 pm
remote file copy using Net::Telnet February 3, 2006, 2:02 am
remote keyboard and mouse IO February 21, 2005, 3:22 am
how to execute command on remote machine September 21, 2005, 12:40 am
Remote install of Perl Module April 12, 2005, 10:47 am
Read user log from a remote host July 26, 2006, 5:14 am
Net::SSH::Perl to connect to a remote server via a web page August 30, 2004, 10:02 am
SOAP::Lite creating remote objects March 29, 2006, 9:51 am
SOAP::WSDL error accessing remote site. July 19, 2007, 3:14 am
Is there a module that grabs a remote page and prints thumbnail image? May 26, 2006, 12:09 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap