Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Password request on RCP?

by hydo (Monk)
on Sep 01, 2000 at 11:50 UTC ( [id://30691]=perlquestion: print w/replies, xml ) Need Help??

hydo has asked for the wisdom of the Perl Monks concerning the following question:

In a script that I am writing I have to rcp a file to another machine. When I test the rcp in a shell it works just fine. But when I do it in perl I always get asked for a password. Anyone have any idea why?
I dont know what rcp would be looking for in my environment, but i'm not sure what else it could be.

Quick example:

my $rcp_command = "rcp $file $username@$hostname:$destfile";
system( $rcp_command );

Pretty simple. Again, if I print() $rcp_command and then cut/paste it to a shell it works without a problem. Also please note that I cannot install any modules on these machines.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Password request on RCP?
by ncw (Friar) on Sep 01, 2000 at 14:01 UTC
    You haven't got warnings enabled have you?

    You wrote

    my $rcp_command = "rcp $file $username@$hostname:$destfile"; # perl will be interpreting this ^ system( $rcp_command );
    Try printing the value of $rcp_command

    Next time - enable warnings! Perl will then give you all sorts of errors about that line.

    Also I would suggest you always use the array form of system when you don't need to use the shell, eg

    system("rcp", $file, "$username\@$hostname:$destfile") == 0 or die "Failed to rcp: $?"
    This way you won't get your bacon sliced when shell metacharacters get into $file.

    Update: actually you need to be using use strict to see a warning here. You'll see something like Can't use string ("host") as an ARRAY ref while "strict refs" in use.

      I guess I should have put more of the script up.
      I am escaping '@', I am using strict, I am printing the value of $rcp_command, and I do have warnings enabled.
      Those two lines were from memory and not a cut/paste.
        CRAP! Lets try that again.
        #!/opt/perl5/bin/perl -w use strict; use File::Copy; my $VERSION = 0.2; my $cTestMode = 0; my $cVerbose = 0; my $cContinueOnError = 0; if ( @ARGV ) { foreach ( @ARGV ) { if ( ( $_ eq "-help" ) || ( $_ eq "-h" ) ) { kHelpMessage(); exit( 0 ); } if ( ( $_ eq "-test" ) || ( $_ eq "-t" ) ) { $cTestMode = 1; next; } if ( ( $_ eq "-verbose" ) || ( $_ eq "-v" ) ) { $cVerbose = 1; } if ( ( $_ eq "-continue" ) || ( $_ eq "-c" ) ) { $cContinueOnError = 1; } if ( ( $_ eq "-list" ) || ( $_ eq "-l" ) ) { kListModules(); } if ( $_ eq "-shell" ) { kExecShell(); } if ( $_ eq "-version" ) { print( "version $VERSION\n" ); exit( 0 ); } if ( $_ eq "-exec" ) { exit( 0 ); } } } # create the suffix for backups... my @cTimeNow = localtime( time() ); my $cTimeSuffix = "$cTimeNow[ 4 ]$cTimeNow[ 3 ]$cTimeNow[ 5 ]"; my $cDestAPath = "/apath"; my $cDestBPath = "/bpath"; my $cFilesADir = "/adir"; my $cFilesBDir = "/bdir"; my $cRSHUsername = 'rshuser'; my $cRSHHostname = 'rshhost'; my %files = ( "fact_bucket.txt" => "a", "fact_collab.txt" => "a", "fact_collab_to_delete.txt" => "a", "part_number_to_delete.txt" => "a", "resource_to_delete.txt" => "a", "site_to_delete.txt" => "a", "broker_customer_supplier.txt" => "b", "mailing_list.txt" => "b", "part_number.txt" => "b", "broker_supplier.txt" => "b", "resource.txt" => "b", "domain.txt" => "b", "role.txt" => "b", "broker_upDnMember.txt" => "b", "broker_upDnMemberFile.txt" => "b", "broker_upDnMemberFileDm.txt" => "b", "role_info.txt" => "b", "org.txt" => "b", "item_attribute.txt" => "b", "site.txt" => "b" ); my( $new_name, $copy_source, $copy_dest, $rcp_command, $cFileRemoteCom +pareCommand, $cFileLocalCompareCommand ); foreach ( keys( %files ) ) { if ( $files{ $_ } eq "a" ) { $new_name = "$_.$cTimeNow[4]$cTimeNow[3]$cTimeNow[5]"; $copy_source = "$cFilesADir/$_"; $copy_dest = "$cDestAPath/$new_name"; $rcp_command = "rcp $cFilesADir/$_ $cRSHUsername\@$cRSHHostnam +e:$cDestAPath/$_"; $cFileRemoteCompareCommand = "rexec $cRSHHostname /usr/bin/cks +um $cDestAPath/$_"; $cFileLocalCompareCommand = "/usr/bin/cksum $cFilesADir/$_"; } else { $new_name = "$_.$cTimeNow[4]$cTimeNow[3]$cTimeNow[5]"; $copy_source = "$cFilesBDir/$_"; $copy_dest = "$cDestBPath/$new_name"; $rcp_command = "rcp $cFilesBDir/$_ $cRSHUsername\@$cRSHHostnam +e:$cDestBPath/$_"; $cFileRemoteCompareCommand = "rexec $cRSHHostname /usr/bin/cks +um $cDestBPath/$_"; $cFileLocalCompareCommand = "/usr/bin/cksum $cFilesBDir/$_"; } if ( $cVerbose ) { print( "MSG: new_name: $new_name\nMSG: copy_source: $copy_sour +ce\nMSG: copy_dest: $copy_dest\nMSG: rcp_command:\n" ); kPrintArray( $rcp_command ); print( "MSG: RemoteCompare: $cFileRemoteCompareCommand\n" ); } $cTestMode ? kError( "TESTMODE: would have copied $copy_source to +$copy_dest" ) : copy( $copy_source, $copy_dest ); if ( $cTestMode ) { kError( "TESTMODE: did not execute RCP." ); kPrintArray( $rcp_command ); } else { # __exec( $rcp_command ); my $ret_res=`$rcp_command`; } if ( !$cTestMode ) { # the kludge bunnies begin screaming about here... # This wouldn't be so bad if I could Net::RSH this or somethin +g but oh well... my $cRemoteCompareResult = `$cFileRemoteCompareCommand`; my $cLocalCompareResult = `$cFileLocalCompareCommand`; my $z = kSplitCheck( $cRemoteCompareResult ); my $x = kSplitCheck( $cLocalCompareResult ); if ( $z == $x ) { if ( $cVerbose ) { print( "copied $_ correctly.\n" ); } } else { kError( "MAIN: remote checksum does not match local one.\n +Local: $x\nRemote: $z\n" ); if ( !$cContinueOnError ) { exit( 1 ); } } } else { kError( "TESTMODE: not executing chksum comparison." ); } } # # Should I make this return 0/1 or should it have output? That is the + question... # # for now, it's pretty bad. sub __exec { system( shift() ); } sub kError { print( "ERROR:", shift(), "\n" ); } sub kSplitCheck { my @thing = split( ' ', $_ ); if ( $#thing != 2 ) { kError( "kSplitCheck: passed value != 2 when split." ); if ( !$cContinueOnError ) { kError( "kSplitCheck: stopping on error." ); exit( 1 ); } } return( $thing[ 0 ] ); } sub kHelpMessage { print( "Usage:\nchkfiles [ option ] function\n\n" ); print( "Options:\n\t-v -verbose: Show lots of output.\n" ); print( "\t-h or -help: Show this message.\n" ); print( "\t-t or -test: Just test. Dont actually copy anything.\n" + ); print( "\t-c or -continue: Continue despite all errors.\n" ); print( "\t-l or -list: List all runnable scripts.\n\n" ); } sub kPrintArray { my @h = shift(); my $m = join( ' ', @h ); print( "$m\n" ); }
        It's amazing how many errors you notice when you are about to put your code up for public scrutiny. Hopefully everyone wont get so carried away correcting parts of the code that are inefficient that they forget about my origional problem.

        Again, thanks in advance.

        -cm

Re: Password request on RCP?
by hydo (Monk) on Sep 01, 2000 at 22:41 UTC
    Oh that's cute. I posted the code and now it's deleted and I lost experience? What a big help!
    No mention as to WHY this happened... it just happened.
Re: Password request on RCP?
by hydo (Monk) on Sep 01, 2000 at 22:53 UTC
    oh btw, the correct answer is 'remsh' instead of 'rsh'.

    -cm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://30691]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-29 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found