I just found Perl monks, and this is a cool site. I am going to get busted at work if I don't stop checking it. Anyway, I wrote my first real Perl script, and the damn thing actually works, but I would like it to work better and more efficiently. I wrote this script to search through the firewall log files for common trojan ports (Back Orifice, Netbus). Here are the two questions that I have: 1.) Is there a way that I can group all of the "print if" statements together in my while loop? 2.) I also want to add something to where if it does create the file "trojan.log" with a size greater then 0, then to email me. Right now, I am just having a cron job emailing me regardless of the size of the file. I think I can do this with a ls -al and assign the values to a hash. Thanks in advance to all the Perl Yodas who help me. Here is the script:
#!/bin/nsperl # # Search the log files for Back Orifice and Netbus ports open (FILEOUT,">trojan.log") || die "Can't open trojan.log: $!\n"; $oldfile = select(FILEOUT); chomp($DATE=`date +%d%b%y`); #print "Today's date is $DATE", ; $LOGFILE="$DATE.elog"; print "\nThis is the log file $LOGFILE\n\n"; open (FWLOG, "$LOGFILE")|| die "Can't open $LOGFILE: $!\n"; while(<FWLOG>){ print "$_" if /\b12345\b/; print "$_" if /\b12346\b/; print "$_" if /\b20034\b/; print "$_" if /\b8787\b/; print "$_" if /\b31337\b/; print "$_" if /\b31338\b/; print "$_" if /\b54320\b/; print "$_" if /\b54321\b/; } close (FILEOUT); close(FWLOG);
-Dru

In reply to I want to be a Perl Jedi 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.