Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

RE: RE: Password request on RCP?

by hydo (Monk)
on Sep 01, 2000 at 20:55 UTC ( #30751=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Password request on RCP?
in thread Password request on RCP?

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

Replies are listed 'Best First'.
RE: RE: RE: Password request on RCP?
by ncw (Friar) on Sep 01, 2000 at 21:47 UTC
    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 ;-)

      ok. How does it look to you now? It was ok for me but then again I have my browser maximized on a 1280x1024 screen w/ small fonts.
        That looks fine now!

        I can only think of one thing - are you su-ing to root maybe to run this test program? Maybe the fact that your stored and effective uid are different causes problems when you run rsh from perl (which is starting another shell to do it?). Therefore rsh thinks you are someone else and asks you for the password.

        You could try my suggestion of running the system() with an array of things in so as not to invoke another shell - this might help. Then again it might be perl doing it...

        I always use scp/ssh for this sort of thing and I've never had a problem with it like that. You might need to put a -n on the rsh command line if you run it from a crontab though.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2023-09-26 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?