Remote.pm (File::Remote) problem

Discussion in 'Perl Misc' started by Dayton Jones, Mar 1, 2006.

  1. Dayton Jones

    Dayton Jones Guest

    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...
    Dayton Jones, Mar 1, 2006
    #1
    1. Advertising

  2. Dayton Jones <> wrote in
    news::

    > 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 <>
    (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
    A. Sinan Unur, Mar 1, 2006
    #2
    1. Advertising

  3. Dayton Jones

    Dayton Jones Guest

    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 <> wrote in
    > news::
    >
    >
    >>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
    >
    Dayton Jones, Mar 1, 2006
    #3
  4. Dayton Jones <> wrote in
    news::

    > A. Sinan Unur wrote:
    >> Dayton Jones <> wrote in
    >> news::
    >>
    >>
    >>>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 <>
    (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
    A. Sinan Unur, Mar 1, 2006
    #4
  5. Dayton Jones

    Dayton Jones Guest

    Yes, I noticed that when reading your original response -- changed it to
    "setrcp="

    A. Sinan Unur wrote:
    > Dayton Jones <> wrote in
    > news::
    >
    >
    >>A. Sinan Unur wrote:
    >>
    >>>Dayton Jones <> wrote in
    >>>news::
    >>>
    >>>
    >>>
    >>>>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
    >
    Dayton Jones, Mar 1, 2006
    #5
  6. Dayton Jones <> wrote in
    news::

    Dayton, *please* do not top-post.

    > A. Sinan Unur wrote:
    >> Dayton Jones <> wrote in
    >> news::
    >>
    >>
    >>>A. Sinan Unur wrote:
    >>>
    >>>>Dayton Jones <> wrote in
    >>>>news::
    >>>>
    >>>>
    >>>>> 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 <>
    (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
    A. Sinan Unur, Mar 1, 2006
    #6
  7. 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
    harryfmudd [AT] comcast [DOT] net, Mar 2, 2006
    #7
  8. Dayton Jones

    Dayton Jones Guest

    A. Sinan Unur wrote:
    > Dayton Jones <> wrote in
    > news::
    >
    > Dayton, *please* do not top-post.
    >
    >
    >>A. Sinan Unur wrote:
    >>
    >>>Dayton Jones <> wrote in
    >>>news::
    >>>
    >>>
    >>>
    >>>>A. Sinan Unur wrote:
    >>>>
    >>>>
    >>>>>Dayton Jones <> wrote in
    >>>>>news::
    >>>>>
    >>>>>
    >>>>>
    >>>>>>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.
    Dayton Jones, Mar 2, 2006
    #8
  9. Dayton Jones <> wrote in news:4N-dnaBMS9EUiZrZRVn-
    :

    > A. Sinan Unur wrote:

    ....

    >>>>>A. Sinan Unur wrote:
    >>>>>
    >>>>>
    >>>>>>Dayton Jones <> wrote in
    >>>>>>news::
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>>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 <>
    (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
    A. Sinan Unur, Mar 2, 2006
    #9
  10. Dayton Jones

    Dayton Jones Guest

    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...
    Dayton Jones, Mar 3, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cmV5Y29u?=

    can't access file on a remote file server

    =?Utf-8?B?cmV5Y29u?=, Jun 3, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,072
    agrnidhi
    May 24, 2007
  2. davidj411
    Replies:
    7
    Views:
    3,252
    Tim Golden
    Oct 8, 2009
  3. Tim Chandler
    Replies:
    0
    Views:
    208
    Tim Chandler
    Oct 7, 2003
  4. Jeff Wood
    Replies:
    7
    Views:
    193
    Jeff Wood
    Oct 18, 2005
  5. Markus Arike
    Replies:
    2
    Views:
    97
    Markus Arike
    Aug 19, 2008
Loading...

Share This Page