Hey Monks,

I have this script almost completed. I have a foreach loop that will subsitute my firewall's ip address with x's and also only include the first 15 lines from the firewall log in the email that I send to the sysadmin (as evidence). Within the here document, the foreach loop is not completely working. It includes the full snapshot without replacing the firewall's ip address and it does not cut off at 15 lines. If I just print it to STDOUT, then everything is kosher. Can somebody let me know what I am doing wrong? I tried everything that I can think of. Thanks in advance,

-Dru
---------First Part of Script Not Included------------- my $ip = qr/\b$ips[0][0]\b/o; my @fwlog; my $logfile = "/home/jdoe/scripts/fwanalysis/05jul01.drop"; open LOG, "$logfile" or die "Can't open $logfile: $!\n"; while (<LOG>){ if ($_ =~ $ip){ push (@fwlog, $_); } #end if } #end while close LOG; my $i = 0; open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<EOM; From: root<root\@localhost> To: root<root\@localhost> Subject: Flagged Activity I am the Network Security Manager for ACME INC. While I was performing + a scan through our logs I found an ip from you network trying to hac +k us. Cease or be destroyed. Source IP Address: $ips[0][0] Sample from the firewall logs: foreach (@fwlog){ s/192.168.2.3/x.x.x.x/; print $_; if($i++ >15){ last } }#end foreach EOM close(SENDMAIL) or warn "sendmail didn't close nicely";

In reply to Foreach loop not working within Mail by dru145

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.