Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Remote.pm (File::Remote) problem

Reply
Thread Tools

Remote.pm (File::Remote) problem

 
 
Dayton Jones
Guest
Posts: n/a
 
      03-01-2006
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 File::Remote qw(:replace);

setrsh('/usr/bin/ssh');
serrcp('/usr/bin/scp');
settmp('/tmp');

copy("host1:/tmp/file","host1:/tmp/file2") or die ":: $!\n";

-- end script

On "host1" I can see the connection coming in:
Feb 28 18:46:48 host1 sshd(pam_unix)[20211]: session opened for user
XXXX by (uid=XXX)
Feb 28 18:46:49 host1 sshd(pam_unix)[20211]: session closed for user XXXX


So I don't know what is causing the permissions issue... Any ideas or
suggestions? What do I need to look at, what could be the cause?

Thanks is advance for any help...
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-01-2006
Dayton Jones <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

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


*Ah-em*. Have you read the posting guidelines for this group?

....

> Thanks is advance for any help...


You can learn how to help others help you, and also how to help yourself
by following the posting guidelines.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

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

 
Reply With Quote
 
 
 
 
Dayton Jones
Guest
Posts: n/a
 
      03-01-2006
Sorry, no I hadn't read the guidelines but I will now.

I added the strict/warnings but had the same result -- with no extra
information.

A. Sinan Unur wrote:
> Dayton Jones <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>
>>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');

>
>
> *Ah-em*. Have you read the posting guidelines for this group?
>
> ...
>
>
>>Thanks is advance for any help...

>
>
> You can learn how to help others help you, and also how to help yourself
> by following the posting guidelines.
>
> Sinan
>

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-01-2006
Dayton Jones <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> A. Sinan Unur wrote:
>> Dayton Jones <(E-Mail Removed)> wrote in
>> news:(E-Mail Removed):
>>
>>
>>>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.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

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

 
Reply With Quote
 
Dayton Jones
Guest
Posts: n/a
 
      03-01-2006
Yes, I noticed that when reading your original response -- changed it to
"setrcp="

A. Sinan Unur wrote:
> Dayton Jones <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>
>>A. Sinan Unur wrote:
>>
>>>Dayton Jones <(E-Mail Removed)> wrote in
>>>news:(E-Mail Removed) om:
>>>
>>>
>>>
>>>>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.
>
> Sinan
>

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-01-2006
Dayton Jones <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

Dayton, *please* do not top-post.

> A. Sinan Unur wrote:
>> Dayton Jones <(E-Mail Removed)> wrote in
>> news:(E-Mail Removed):
>>
>>
>>>A. Sinan Unur wrote:
>>>
>>>>Dayton Jones <(E-Mail Removed)> wrote in
>>>>news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast. com:
>>>>
>>>>
>>>>> 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{TEMP});

{
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

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

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

 
Reply With Quote
 
harryfmudd [AT] comcast [DOT] net
Guest
Posts: n/a
 
      03-02-2006
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
 
Reply With Quote
 
Dayton Jones
Guest
Posts: n/a
 
      03-02-2006
A. Sinan Unur wrote:
> Dayton Jones <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> Dayton, *please* do not top-post.
>
>
>>A. Sinan Unur wrote:
>>
>>>Dayton Jones <(E-Mail Removed)> wrote in
>>>news:(E-Mail Removed):
>>>
>>>
>>>
>>>>A. Sinan Unur wrote:
>>>>
>>>>
>>>>>Dayton Jones <(E-Mail Removed)> wrote in
>>>>>news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast .com:
>>>>>
>>>>>
>>>>>
>>>>>>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{TEMP});
>
> {
> 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.
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-02-2006
Dayton Jones <(E-Mail Removed)> wrote in news:4N-dnaBMS9EUiZrZRVn-
http://www.velocityreviews.com/forums/(E-Mail Removed):

> A. Sinan Unur wrote:

....

>>>>>A. Sinan Unur wrote:
>>>>>
>>>>>
>>>>>>Dayton Jones <(E-Mail Removed)> wrote in
>>>>>>news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcas t.com:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>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
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

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

 
Reply With Quote
 
Dayton Jones
Guest
Posts: n/a
 
      03-03-2006
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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments