Good afternoon,
I have a text file that is created on the fly, and it is scanned for a certain pattern as it is created.
One of our co-workers, who has since left, wrote a small script to do this.
If it sees a line that begins with a A, then it looks for a pattern that has DN7xxx where xxx is supposed to be any digit.
Then it compares the 7 digit number at the end of the line to a CSV file. If the number is in the CSV, it shoots an email off to a distribution list, and ftp a file off to somewhere else.
We need to modify this so that it it also looks for numbers that begin with 15xx and 16xx. (where xx can be any digit)
A friend who is good with Perl told me to replace the line:
with
and
with
This second statement is Line 31
However, this will generate an error:
I found that if I added a / to the second statement so that it was thus:
It would compile, but it wouldn't work.
Would someone mind telling me what I'm doing wrong?
I'm attaching the complete modified script, minus the slash's:
I have a text file that is created on the fly, and it is scanned for a certain pattern as it is created.
One of our co-workers, who has since left, wrote a small script to do this.
If it sees a line that begins with a A, then it looks for a pattern that has DN7xxx where xxx is supposed to be any digit.
Then it compares the 7 digit number at the end of the line to a CSV file. If the number is in the CSV, it shoots an email off to a distribution list, and ftp a file off to somewhere else.
We need to modify this so that it it also looks for numbers that begin with 15xx and 16xx. (where xx can be any digit)
A friend who is good with Perl told me to replace the line:
Code:
if ( /^A .*(DN7... ) .*(\d{7,7})/ ){
Code:
if (/^A .*(DN((7\d)|(15)|(16))\d{2}) .*(\d{7,7})/) {
and
Code:
if( $DN =~ /DN7... / ){
Code:
if( $DN =~ DN((7\d)|(15)|(16))\d{2}){
This second statement is Line 31
However, this will generate an error:
Code:
Backslash found where operator expected at sdimon.tmp line 31, near "7\"
(Missing operator before \?)
syntax error at sdimon.tmp line 31, near "7\"
Unquoted string "d" may clash with future reserved word at sdimon.tmp line 31.
Backslash found where operator expected at sdimon.tmp line 31, near ")\"
(Missing operator before \?)
sdimon.tmp had compilation errors.
I found that if I added a / to the second statement so that it was thus:
Code:
if( $DN =~ /DN((7\d)|(15)|(16))\d{2}/){
Would someone mind telling me what I'm doing wrong?
I'm attaching the complete modified script, minus the slash's:
Code:
#!/usr/bin/perl -w
#
$DEV="ttyS0";
$LOGFILE="cdr.log";
$LOGDIR="/var/log"; #change as needed.
$DBFILE="/root/USER.DB";
$SIG{INT}='rr_db';
&rr_db;
if ( ! -e "/dev/$DEV" ){
print "Device: /dev/$DEV not found.\n";
exit;
}
open(SERIAL, "</dev/$DEV") || die "$!\n";
select(SERIAL); $| = 1; select(STDOUT);
while(<SERIAL>){
print "$_";
open(LOG, ">>$LOGDIR/$LOGFILE") || print "Unable to open Logfile. $!\n";
print LOG "$_";
close(LOG);
if (/^A .*(DN((7\d)|(15)|(16))\d{2}) .*(\d{7,7})/) {
$DN = $1;
$PAC = $2;
if( $DN =~ DN((7\d)|(15)|(16))\d{2}){
if (defined $AUTHCODES{$PAC} ){
($NAME,$CLASS,$EXTDN) = split(',', $AUTHCODES{$PAC} );
if ($CLASS ne ("T"|"W")){
open(MAIL, "| mail -s MAXWELL-AUTHCODE-ALERT pacalert") || die "$\n!";
print MAIL "Call from Ext-> $DN \nCurrent PAC CODE Assignment:$PAC
\nName-> $NAME \nDefined As-> $CLASS \nExt-> $EXTDN";
close(MAIL);
#$NOW=`date +%s`;
#chop $NOW;
open(ALERT,">/root/$PAC.PAC");
print ALERT "$PAC";
close(ALERT);
open(FTP,"|/sbin/alertftp");
print FTP "/root/$PAC.PAC\n";
close(FTP);
}
}
}
}
next;
}
close(MAIL);
close(SERIAL);
exit;
sub rr_db {
open(DB,$DBFILE) || die "No user db file. $!\n";
print "Reading User file...\n";
while(<DB>){
chop;
($PAC,$NAME,$CLASS,$DN) = split(',',$_);
$AUTHCODES{$PAC} = "$NAME,$CLASS,$DN";
}
close(DB);
}