Solved

strange simple error

Posted on 2013-12-21
6
283 Views
Last Modified: 2013-12-22
there are 3 part of errors that we get

1. the beginning errors
2. in the code you should see if ($reason eq "mbps" ) {
but it still applie else part of if

3. why do we get numeric  error :S

[root@sflow islemler]# perl deneme.pl
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl line 19.
Unquoted string "trafiklimiti" may clash with future reserved word at deneme.pl line 23.
Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4.
Name "main::trafiklimiti" used only once: possible typo at deneme.pl line 5.
Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23, <$fh> line 1.
paket limiti asildi
mbps

178.20.230.51 35mbps
1387666838 178.20.230.51 35 mbps
paket limiti asildi
pps

178.20.230.51 3072pps
1387666838 178.20.230.51 3072 pps
paket limiti asildi
mbps

178.20.227.86 11mbps
1387666838 178.20.227.86 11 mbps
paket limiti asildi
pps

79.110.81.134 1536pps
1387666838 79.110.81.134 1536 pps
paket limiti asildi
mbps

178.20.230.51 32mbps
1387666839 178.20.230.51 32 mbps
paket limiti asildi
pps

178.20.230.51 3328pps
1387666839 178.20.230.51 3328 pps

Open in new window










use warnings;

 $paketlimiti = 2500;
 $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;
while (my $line = <$fh>) {

#print ((split(/ /, $line))[1],"\n");


my $ip  = (split(/ /, $line))[1];
my $size = (split(/ /, $line))[2];
my $reason = (split(/ /, $line))[3];


if ($reason eq "mbps" ) {
        if ($size >  paketlimiti) {
                print "trafik limiti asildi \n";
        }
}else{
        if ($size >  trafiklimiti) {
                print "paket limiti asildi \n";
        }
}

print $reason . "\n";
print $ip." ".$size.$reason;
print $line;
}

close $fh;

Open in new window

0
Comment
Question by:3XLcom
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
splain
/opt/local/bin/splain: Reading from STDIN
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl line 19.
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl
      line 19 (#1)
    (W reserved) You used a bareword that might someday be claimed as a
    reserved word.  It's best to put such a word in quotes, or capitalize it
    somehow, or insert an underbar into it.  You might also declare it as a
    subroutine.

Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4.
Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4 (#2)
    (W once) Typographical errors often show up as unique variable names.
    If you had a good reason for having a unique name, then just mention it
    again somehow to suppress the message.  The our declaration is
    provided for this purpose.
   
    NOTE: This warning detects symbols that have been used only once so $c, @c,
    %c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
    the same; if a program uses $c only once but also uses any of the others it
    will not trigger this warning.

Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23, <$fh> line 1.
Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23,
      <$fh> line 1 (#3)
    (W numeric) The indicated string was fed as an argument to an operator
    that expected a numeric value instead.  If you're fortunate the message
    will identify which operator was so unfortunate.



Did you mean to say
     if ($size >  $paketlimiti) {
0
 

Author Comment

by:3XLcom
Comment Utility
yes    if ($size >  $paketlimiti) { this part is not wroking correctly check the output

trafik limiti asildi  8>10
178.20.228.75 8mbps
1387668213 178.20.228.75 8 mbps
trafik limiti asildi  8>10
95.7.67.146 8mbps
1387668214 95.7.67.146 8 mbps
trafik limiti asildi  41>10
185.9.156.83 41mbps





#use strict;
use warnings;

my $paketlimiti = 2500;
my $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;
while (my $line = <$fh>) {

#print ((split(/ /, $line))[1],"\n");


my $ip  = (split(/ /, $line))[1];
my $size = (split(/ /, $line))[2] + 0;
my $reason = substr((split(/ /, $line))[3],0,-1);


if ($reason eq 'mbps' ) {
        if ($size >  paketlimiti){
                print "trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }else{
                print "trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }
}else{
        if ($size >  trafiklimiti) {
                print "paket limiti asildi \n";
        }
}

print $ip." ".$size.$reason."\n";
print $line;
}

close $fh;

Open in new window

0
 

Author Comment

by:3XLcom
Comment Utility
that worked but why my variable not acting like a numeric value ;

  
 if ($size >  10){
                print  $size2." trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }else{
                print $size2." trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
If you mean $size, what was its value?
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
Comment Utility
Why did you comment out the use strict; statement?

Ignoring the problems strict points out is never a good practice.

Are you receiving the warning for every line or just some of the lines?

In either case, it would appear that the line is not formatted as you expect.  You should use the Data::Dumper or Data::Dump module to dump out the full line as well as the vars after the splitting the line.

Why are you using 3 separate split statements?  You should assign all 3 of those vars using a single split statement.

I assume you're using substr to remove the line terminator, but why. The normal method to remove the line terminator is to use the chomp function.

You're splitting on a single space, which may be just fine, but just in-case  there is more than a single space separating the fields and to accommodate possible leading spaces, use ' ' instead of / /.

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $paketlimiti = 2500;
my $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;

while (my $line = <$fh>) {
    
    chomp $line;
    my ($ip, $size, $reason)  = (split(' ', $line))[1,2,3];
    
    print Dumper ($line, $ip, $size, $reason);
    
    if ($reason eq 'mbps' ) {
        if ($size > $paketlimiti){
            print "trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }
        else {
            print "trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }
    }
    else {
        if ($size > $trafiklimiti) {
            print "paket limiti asildi \n";
        }
    }
}

close $fh;

Open in new window

0
 

Author Closing Comment

by:3XLcom
Comment Utility
thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now