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
#!/usr/bin/perl -w use strict; my $seculert_qradar_list = "$seculert_dir/seculert.csv"; my $qradar_console = '10.10.1.22'; my $qradar_ssh_key = "$seculert_dir/qr-id_dsa"; my $qradar_ssh_knownhosts = "$seculert_dir/known_hosts"; my $source = 'BAD-IP-Addresses-LABEL'; my $type_description = 'honeypots-for-examnple'; open(FP, ">>$seculert_qradar_list"); for my $line (<FP>) { my ($hostname, $ip, $something1, $something2) = split(/,/, $li +ne); print OUT "$source $type_description $ip #FF0000 0 90 29\n"; } close(FP); 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_knownhos +ts -o StrictHostKeyChecking=no root\@$qradar_console:/store/configser +vices/staging/globalconfig/remotenet.conf .`; `sed -i -e '/^SECULERT/d' remotenet.conf`; `cat $seculert_qradar_list >> remotenet.conf`; `scp -i $qradar_ssh_key -o UserKnownHostsFile=$qradar_ssh_knownhos +ts -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_knownhos +ts -o StrictHostKeyChecking=no root\@$qradar_console /opt/qradar/upgr +ade/util/setup/upgrades/do_deploy.pl`; print "Complete!\n\n";

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 1. virus.csv 2. bot.csv 3. malware.csv

Do i need to re-copy for loop code for each csv file with a different handle? The destination file remotenet.conf remains the same.

After correct rendering of for e.g one csv file the remotenet.conf on web-ui would look something like Virus 10.10.2.1 ....... Bot 10.10.4.1 ...... 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. thanks **UPDATE** Based upon content of csv rendering would change $source and $type_description varies with csv. for e.g malware.csv would have $source ='malware' and $type_description='top 10' and etc


In reply to Multiple csv file rendering by PERL using single file open handle? by asadz

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.