This little gem comes from the logwatch script that reads the fail2ban log. I'm not getting any output, and put the script under the debugger.

while (defined(my $ThisLine = <STDIN>)) { if ( $Debug >= 5 ) { print STDERR "DEBUG($DebugCounter): $ThisLine"; $DebugCounter++; } chomp($ThisLine); if ( ($ThisLine =~ /..,... DEBUG: /) or ($ThisLine =~ /..,... \S*\s*: DEBUG /) or # syntax of 0.7.? f +ail2ban ($ThisLine =~ /..,... INFO: (Fail2Ban v.* is running|Exiting| +Enabled sections:)/) or ($ThisLine =~ /INFO\s+Log rotation detected for/) or ($ThisLine =~ /INFO\s+Jail.+(?:stopped|started|uses poller)/) + or ($ThisLine =~ /INFO\s+Changed logging target to/) or ($ThisLine =~ /INFO\s+Creating new jail/) or ($ThisLine =~ /..,... \S+\s*: INFO\s+(Set |Socket|Exiting|Gam +in|Created|Added|Using)/) or # syntax of 0.7.? fail2ban ($ThisLine =~ /..,... WARNING: Verbose level is /) or ($ThisLine =~ /..,... WARNING: Restoring firewall rules/) ) { if ( $Debug >= 6 ) { print STDERR "DEBUG($DebugCounter): line ignored\n"; } } elsif ( my ($Service,$Host,$NumFailures) = ($ThisLine =~ m/INFO: + (\S+): (.+) has (\d+) login failure\(s\). Banned./)) { if ($Debug >= 4) { print STDERR "DEBUG: Found host $Host trying to access $Se +rvice - failed $NumFailures times\n"; } push @{$ServicesBans{$Service}{$Host}{'Failures'}}, $NumFailur +es; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/ ERROR:\s(.*):\s(\ +S+)\salready in ban list/)) { $ServicesBans{$Service}{$Host}{'AlreadyInTheList'}++; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/WARNING\s*\[(.*)\] +\s*(\S+)\s*already banned/)) { $ServicesBans{$Service}{$Host}{'AlreadyInTheList'}++; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/ WARNING:\s(.*):\s +ReBan (\S+)/)) { $ServicesBans{$Service}{$Host}{'ReBan'}++; } elsif ($ThisLine =~ / ERROR:?\s*(Execution of command )?\'?iptab +les/) { push @IptablesErrors, "$ThisLine\n"; } elsif ($ThisLine =~ /ERROR.*returned \d+$/) { push @ActionErrors, "$ThisLine\n"; } elsif (($ThisLine =~ /..,... WARNING: \#\S+ reinitialization of +firewalls/) or ($ThisLine =~ / ERROR\s*Invariant check failed. Trying to +restore a sane environment/)) { $ReInitializations++; } elsif ($ThisLine =~ /..,... WARNING: is not a valid IP address/ +) { # just ignore - this will be fixed within fail2ban and is harm +less warning } else { # Report any unmatched entries... push @OtherList, "$ThisLine\n"; } }

When I run this under the debugger, and I advance using the "s" command, should I expect the debugger to stop on each of the elsif statements before evaluating it, or should it only stop if the argument is true?

Many Thanks, Ed Greenberg

In reply to If statement seems to ignore elsif and skips to else by edgreenberg

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.