Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Greetings Monks.

I'm hoping someone with more ActivePerl experience that I can shed some light on the behavior that I'm seeing.

I have a script ( below ) that copies some Nessus scans to another machine for further processing.

When I run the script via perl.exe ( >perl copy_files.wpl ) it runs perfectly.

When I run it via wperl.exe, either on the command line ( >wperl copy_files.wpl ) or via Windows Task Scheduler, it fails with the error: Unable to connect to remote host: Bad ssh command: Invalid argument at C:\Users\Administrator\RiskView\copy_files.wpl line 76.

I believe I have all the required tweaks for wperl - suppressing the window, redirecting STDERR and STDOUT to files, but as wperl.exe is supposed to be identical to perl.exe except for the need to launch a window, I'm at a loss to explain why it won't run the Net::SFTP::Foreign module without error.

As always, thanks for any input!

Best regards, Scott...

file_copy.wpl:

use strict; use warnings; use Date::Manip; use Archive::Zip; use Net::SFTP::Foreign; use Data::Dumper; BEGIN { Win32::SetChildShowWindow(0) if defined &Win32::SetChildShowWindow +; } my $producer = "file_copy"; my $output_log = $producer . "_output_log.log"; my $error_log = $producer . "_error_log.log"; my $copy_log = $producer . "_log.log"; unlink( $error_log ); unlink( $output_log ); close(STDOUT); open(STDOUT, ">>$output_log"); close(STDERR); open(STDERR, ">>$error_log" ); # Nessus directory my $nessus_dir = '/opt/sc4/orgs/1/VDB'; my $incoming_dir = 'C:\\Users\\Administrator\\Incoming'; # Data file directory my $data_dir = 'C:\\Users\\Administrator\\Data'; my $host = '10.10.10.10'; my $user = 'user'; my $password = 'password'; # Check the copylog for the last set of files loaded my $last_loaded_date; open ( LOG_DATA, "<$copy_log"); while ( my $line = <LOG_DATA>) { chomp $line; next unless( $line =~ /Last Loaded/ ); my @last_loaded_time_line = split( /:/, $line ); $last_loaded_date = $last_loaded_time_line[1]; last; } close ( LOG_DATA); print "Getting files more recent than $last_loaded_date\n"; my $dm1 = new Date::Manip::Date; my $dm2 = $dm1->new_date; my $now_date = $dm1->new_date; my $time_stamp = time; my $err = $now_date->parse( "epoch $time_stamp" ); my $current_date = $now_date->printf( "%Y-%m-%d %H:%M:%S" ); $last_loaded_date =~ s/^\s+//; $last_loaded_date =~ s/\s+$//; $dm1->parse( $last_loaded_date ); my $sftp = Net::SFTP::Foreign->new( $host, user => $user, password => +$password, ssh_cmd => 'plink' ); $sftp->error and die "Unable to connect to remote host: " . $sftp->err +or; # Get the files chdir $incoming_dir; my @ls1 = @{ $sftp->ls( $nessus_dir, names_only => 1, ordered => 1 ) } +; my $last_loaded; foreach my $dir_date ( @ls1 ) { next unless $dir_date =~ /\d{4}-\d{2}-\d{2}/; $dm2->parse( $dir_date ); if ( $dm1->cmp( $dm2 ) == -1 ) { $sftp->mget( "$nessus_dir/$dir_date/*nessus-results.zip" ) or +die "Unable to transfer files: " . $sftp->error; $last_loaded = $dir_date; print "Getting files from directory $dir_date\n"; } } undef $sftp; open( LOG,">../$copy_log ") or die $!; print LOG "Copied Nessus reports from SecurityCenter\n"; print LOG "Last copy run on: $current_date\n"; print LOG "Last Loaded (directory name): $last_loaded\n"; close( LOG );

In reply to ActivePerl - perl.exe works, wperl.exe does not... by spstansbury

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-18 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found