Oops, sorry for the empty reply. 

Greg,
It is a common misconception that regular expressions act like text. If you are 
looking for this string:

NAS-IP-Address = "192.168.0.1"

you must escape all the special characters like this:


NAS\-IP\-Address = \"192\.168\.0\.1\"

Quotes do not work within regexp, periods find any character, I believe the minus sign 
also has special meaning. 

The regexp above is still not really good because it assumes one space before and 
after the equal sign. This would be better:

NAS\-IP\-Address\s*=\s*\"192\.168\.0\.1\"

Now zero or more whitespace characters may separate the text from the equal sign on 
both sides.

Bill

-----Original Message-----
From: Greg Schiedler [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 18, 2004 2:16 PM
To: [EMAIL PROTECTED]
Subject: next if statement....


OK I'm trying to modify the code below to recognize an additional next if statement.  
I have
included a snip of the file that the code uses an input.

Greg

next if /Acct-Session-Id = "00000000"/;    This statment works!

# I added this statement.  I don't understand the /'s in the statement.  And my guess 
is that
I need to modify the statement to properly work with an IP over a number or string.

next if /NAS-IP-Address = "192.168.0.1"/;  This statement does not work.

next if /User-Name = "$userskp"/;          This statement works!

Can anyone tell me why my simple addition will not work as I think it should.

Greg :-)


<Code Snipit>
...
...
require 'usrmon.cf';

if (-M "$file" < .04) {

  $date= (localtime)[3];

  dbmopen(%hash, "$dbfile", 0600);

  open (FILE, "$file") || die;
  open (FILEBK, ">>$filebk") || die;
  while (<FILE>) {
    $/ = '';
    next if /Acct-Session-Id = "00000000"/;
    next if /NAS-IP-Address = "192.168.0.1"/;
    next if /User-Name = "$userskp"/;
    print FILEBK;

    if (/Acct-Status-Type = Stop/ || /Acct-Status-Type = Start/) {
      if (/User-Name = "([^"]+)"/){
        $key= $1;
      }
      if (/Acct-Status-Type = Stop/) {
        if (/Acct-Session-Time = (\d+)/) {
          $used{$key}+= $1;
          $uses{$key}++;
        }
      }
    }
  }
  close(FILE);
  open (FILE, ">$file");
  print FILE "\n";



<RADIUS Log Snip>
...
...     Ascend-PreSession-Time = 27
        CVX-Modem-Begin-Modulation = "V.90"
        CVX-Modem-Error-Correction = "V.42"
        CVX-Modem-Data-Compression = "V.42bis"
        Timestamp = 1075939364
        Timestamp = 1075939362

Wed Feb  4 16:03:11 2004
        Acct-Status-Type = Start
        User-Name = "[EMAIL PROTECTED]"
        Acct-Session-Id = "0000062A"
        Framed-IP-Address = 10.0.0.2
        NAS-IP-Address = 192.168.0.1
        Timestamp = 1075939456
        Acct-Delay-Time = 0
        Timestamp = 1075939391

Wed Feb  4 16:04:00 2004
        Acct-Status-Type = Stop
        User-Name = "[EMAIL PROTECTED]"
        Acct-Session-Id = "0000062A"
        Acct-Session-Time = 49
        Framed-IP-Address = 10.0.0.2
        NAS-IP-Address = 192.168.0.1
        Timestamp = 1075939505
        Acct-Delay-Time = 0
        Timestamp = 1075939440

Wed Feb  4 16:04:21 2004
        Acct-Status-Type = Start
        NAS-Identifier = "cvx00.domain.com"
...
...
<End RADIUS Log Snipit>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to