Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple csv file rendering by Perl using single file open handle?
    text
    copied!<p>I have this code, where I want to handle multiple csv(currently its just one file) file and use perl to render its format before its shipped to a linux-box and replaces original file content using ssh connection. Here is the code</p> <pre><code>#!/usr/bin/perl -w use strict; # this is a csv which will contains IP addresses of one specific category for e.g malware. my $seculert_qradar_list = "$seculert_dir/seculert.csv"; #ssh connection information my $qradar_console = '10.10.1.22'; my $qradar_ssh_key = "$seculert_dir/qr-id_dsa"; my $qradar_ssh_knownhosts = "$seculert_dir/known_hosts"; ################################################################################# # NOTE: this is the "OUT" file. # 1 - Name # 2 - Sub-Name # 3 - IP Address # 4 - is colour, deprecated # 5 - database length, deprecated # 6 - asset weight, deprecated # 7 - an ID for the 'record' each unique name pair (first 2 columns) gets an ID ################################################################################# my $source = 'BAD-IP-Addresses-LABEL'; my $type_description = 'honeypots-for-examnple'; # Based upon the format described above I want to render the csv as written in print OUT statement. This format is important, because the endsystem process the file (remotenet.conf) based upon the provided layout. open(FP, "&gt;&gt;$seculert_qradar_list"); for my $line (&lt;FP&gt;) { my ($hostname, $ip, $something1, $something2) = split(/,/, $line); print OUT "$source $type_description $ip #FF0000 0 90 29\n"; } close(FP); # Here I just want the contents of modified csv to be written over remotenet.conf. This file is then processed through auto-deploy script by the system. The results get populated on front-end webserver. print "Sending to QRadar...\n"; # SSH To QRadar's Console and push out file + trigger update `scp -i $qradar_ssh_key -o UserKnownHostsFile=$qradar_ssh_knownhosts -o StrictHostKeyChecking=no root\@$qradar_console:/store/configservices/staging/globalconfig/remotenet.conf .`; `sed -i -e '/^SECULERT/d' remotenet.conf`; `cat $seculert_qradar_list &gt;&gt; remotenet.conf`; `scp -i $qradar_ssh_key -o UserKnownHostsFile=$qradar_ssh_knownhosts -o StrictHostKeyChecking=no remotenet.conf root\@$qradar_console:/store/configservices/staging/globalconfig/remotenet.conf`; print "Cleaning up...\n"; # Remove our SECULERT list and the newly pushed out qradar conf unlink($seculert_qradar_list); unlink ('remotenet.conf'); print "Deploying in QRadar...(takes time to complete)\n"; # QRadar magic `ssh -i $qradar_ssh_key -o UserKnownHostsFile=$qradar_ssh_knownhosts -o StrictHostKeyChecking=no root\@$qradar_console /opt/qradar/upgrade/util/setup/upgrades/do_deploy.pl`; print "Complete!\n\n"; </code></pre> <p>What I'm interested to know and perhaps get some help from perl programmer that using one file handle can I open multiple files e.g In my case I have something like this</p> <ol> <li>virus.csv </li> <li>bot.csv </li> <li>malware.csv</li> </ol> <p>Do i need to re-copy for loop code for each csv file with a different handle? The destination file <code>remotenet.conf</code> remains the same.</p> <p>After correct rendering of for e.g one csv file the remotenet.conf on web-ui would look something like</p> <pre><code>Virus 10.10.2.1 ....... Bot 10.10.4.1 ...... </code></pre> <p>It would be great that multiple changes happen in one-go, with just one auto-deploy(see code at end). I hope I'm able to understand the problem. Please let me know if more clarification is required.</p> <p>thanks</p> <p><strong>WHAT I WANT TO ACCOMPLISH</strong></p> <p>I want a dynamic code, where there are multiple csv ready for rendering kept inside one folder. The sequence is described as :-</p> <ol> <li>read each csv file from folder.</li> <li>converts it into the acceptable format.</li> <li>Change two variables values based upon csv file name. For e.g </li> </ol> <p><strong>For filename malware.csv</strong></p> <p>my $source = 'BAD-IP-Addresses-LABEL'; my $type_description = 'honeypots-for-examnple';</p> <p><strong>For bot.csv</strong></p> <p>my $source = 'bot-net'; my $type_description = 'top-10';</p> <p>At end, copies the formated file along with contents into remotenet.conf through ssh.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload