Что-то я намудрил в предыдущем посте.
Это как не надо делать. ))
Всё оказалость гораздо проще. Может ещё пригодится.
На perl
#!/usr/bin/perl
use strict;
use warnings;
my @array;
my $file = "/tmp/file";
open ( FH, $file ) or die "couldn't open $file : $!";
while ( <FH> ) {
chomp;
if ( /ip-up ppp\d+/ ) {
/^.*(\d{2}:\d{2}:\d{2}).*\s(ppp(\d+))\s([a-zA-Z0-9]*)\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
push @{$array[$3]}, "$1 $4 $5";
}
if ( /ip-down ppp\d+/ ) {
/^.*(\d{2}:\d{2}:\d{2}).*\s(ppp(\d+))$/;
push @{$array[$3]}, $1;
}
}
close FH;
for my $arrayref (@array) {
print join (" ", @{$arrayref} ), "\n" if defined ( length $arrayref );
}
На php
<?php
$file = "/tmp/file";
$fp = fopen ( $file, "r" ) or die ( "Couldn't open $file" );
while ( ! feof ( $fp ) ) {
$line = fgets ( $fp );
if ( preg_match ( '/ip-up ppp\d+/', $line ) ) {
preg_match ( '/^.*(\d{2}:\d{2}:\d{2}).*(ppp(\d+))\s([a-zA-Z0-9]*)\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/', $line, $logon );
$ifaces[$logon[3]] = array($logon[1], $logon[4], $logon[5]);
}
if ( preg_match ( '/ip-down ppp\d+/', $line ) ) {
preg_match ( '/^.*(\d{2}:\d{2}:\d{2}).*(ppp(\d+))$/', $line, $logoff );
array_push($ifaces[$logoff[3]], $logoff[1]);
}
}
foreach ( $ifaces as $iface ) {
foreach ( $iface as $val ) {
print $val . " ";
}
print "\n";
}
?>