Tor Hildrum <mailto:[EMAIL PROTECTED]> wrote:
> Unless your going to ask for help with some
> actual code you have written, this is better suited
> for [EMAIL PROTECTED]
Ok, thanks and sorry.
In that case:
Update: I've discovered that I can't do network stuff right now, but I can
send
the call tickets to the serial port.
I've found a short perl script called "readserial" that will read a line
from a
serial port and send it to a log.
The problem is that the serial port I'm reading from is also the serial
console
of the phone system, so it gets alarms, login messages, etc. I've disabled
getty from that line, but it's still getting some kernel messages and
whatnot.
The call records are of the form (I'm including eight records, each record
is
on two lines, I have also obfuscated names and numbers):
|6627 |W******* Kady | |0501190943|000:01:27| 0| S
|0|
| |5875555 |N| | 0|001001|001001| 100|
15|B|A|
|6525 |Integrity Fax | |0501190944|000:00:30| 0|
|0|
| | Incoming Call |N| | 0|001001|001001| 100|
0|B|E|
|6625 |E******** Don | |0501190945|000:00:46| 0| S
|0|
| |5185555 |N| | 0|001001|001001| 100|
18|B|A|
|6612 |Mark L****** | |0501190946|000:00:11| 0| S
|0|
| |2655555 |N| | 0|001001|001001| 100|
19|B|A|
|6612 |Mark L****** | |0501190948|000:01:15| 0| S
|0|
| |2655555 |N| | 0|001001|001001| 100|
20|B|A|
|6608 |Karin S****** | |0501190951|000:01:33| 0| S U
|0|
|6601 |3143085555 |N| | 0|001001|001001| 100|
21|B|A|
|FS100 |External | |0501190951|000:02:22| 0|
|0|
|6601 |3143045555 |N| | 0|001001|001001| 100|
0|B|E|
|6521 |Main Fax | |0501190954|000:00:50| 0|
|0|
| |18003965555 |N| | 0|001001|001001| 100|
0|B|E|
(If anyone is interested, or if it's necessary, I can provide a key as to
what
each field is used for.)
And here's an example of the other types of messages I get on that line:
19/01/05 10:02:15 001001M|--/--/-/---|=2:0276=External accounting
application ???: NO RECOVERY
19/01/05 10:11:53 001001M|--/--/-/---|=3:1125=External alarm: "p***** login"
18/01/05 23:35:24 001001M|--/--/-/---|=2:0275=ACCOUNTING: Appli ACCOUNTING:
feature incident 2015
18/01/05 23:35:24 001001M|--/--/-/---|=2:0275=ACCOUNTING: Appli PRINTING:
feature incident 2015
18/01/05 23:35:24 001001M|--/--/-/---|=0:2663=IPC CHORUS err: appli SAVE
oper 20 err 15
18/01/05 23:35:24 001001M|--/--/-/---|=2:0275=ACCOUNTING: Appli ASCII:
feature incident 2015
Command "INTERNAL_TAX" (pid 1133) exited with status 159.
Plus, if I need to reboot the system I get all the shutdown and boot
messages:
Stopping the trace system: /etc/rc6.d/K02emulation(2): che_flushtrace
shutdown
[FAILED]
Removing the chorus/mix emulation layer: a4400emul: Device or resource busy
/etc/rc6.d/K02emulation(2): Removing the chorus/mix emulation layer:
[FAILED]
Stopping xinetd: /etc/rc6.d/K50xinetd(1): xinetd shutdown
[ OK ]
Stopping at daemon: /etc/rc6.d/K60atd(1): atd shutdown
[ OK ]
(Etc...)
I'm trying to start simple, so I'm going to say that if the line contains
|N| or |0| it is part of a call record, so I want to log it. If it's not
I discard (or, optionally, log to a seperate file).
So, I have the following chunk of code:
if( length( $inbuff ) > 0 ){
if ($inbuff =~ m/\|[BNPG]\||\[0A-Z]\|$/){
open( LOG, ">>$log" );
print LOG "$inbuff" ;
close( LOG );
}
}
Which works, but I can't shake the feeling that that regex could be better
given
the input. But I'm just starting out here and pretty new to complex regular
expressions. I think what I've done means "match any single instance of B
or N
or P or G surrounded by | symbols, OR match any single 0 or A through Z
surrounded
by | symbols at the end of a line. Does my thinking match up with my code?
Does
anyone have any suggestions to make the regex better, given the input
provided?
Also, the goal here is to split these records up in order to shove the
fields into
a database. I think I'll start by just writing a csv file, but since two
lines are
one record and the fields are different on each line, I need a way to
determine
which is the first line and which is the second line in each record. The
third
field on the second line will always be one of B, N, P or G surrounded by |
symbols.
I know I can match that with \|[BNPG]\| but how do I match that in a
particular
location? Ie, character 31 is a |, char 32 is one of [BNPG] and character
33 is
another |.
And lastly, I've got an example of splitting stuff up like:
sub splitline {
my $in = $_[0];
my %line =();
if ($in =~ /someregex #data1
otherregex #data2
thirdregex #data3
/x)
{
$line{'data1'} = $1;
$line{'data2'} = $2;
$line{'data3'} = $3;
return %line;
} else { return (); }
}
How do I make those expressions be "characters 2-10 = data1" and "characters
12-
27 = data2", etc. Is there any way to specify the number of characters from
the beginning of the line in perl?
Thanks for any suggestions. Also, sorry this turned out so long.
--J(K)
Here is the whole "readserial" script, as I'm using it right now:
#!/usr/bin/perl
$rc="/usr/local/etc/pblogan.rc";
do $rc || die "No existe configuracion base [$rc] ...\n" ;
open("portfh","+<$port") || die "opening $port for input: $!";
system("stty $psetting < $port");
while(1) {
getmsg( "portfh" );
sleep( 1 );
}
close("portfh");
sub getmsg {
local $portfh = @_;
local($inbuff,$rin) = ('','');
vec($rin,fileno("portfh"),1) = 1;
while ( select($rin, undef, undef, 0.3) ) {
$char = '';
sysread ("portfh",$char,1);
$inbuff .= $char;
}
if( length( $inbuff ) > 0 ){
if ($inbuff =~ m/\|[BNPG]\||\[0A-Z]\|$/){
open( LOG, ">>$log" );
print LOG "$inbuff" ;
close( LOG );
}
}
return;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>