Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Password request on RCP?

by ncw (Friar)
on Sep 01, 2000 at 14:01 UTC ( [id://30697]=note: print w/replies, xml ) Need Help??


in reply to Password request on RCP?

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.

Replies are listed 'Best First'.
RE: Re: Password request on RCP?
by hydo (Monk) on Sep 01, 2000 at 18:43 UTC
    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

        I'm afraid this has become mashed too. Best to post code between <CODE> </CODE> tags otherwise any [ or ] will get mangled. The full details are here.

        You can also go back and edit something you posted (this isn't usenet ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found