bajangerry has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use IO::Socket; use POSIX; use Config::Simple; use DBD::mysql; for(;;){ # Reading configuration parameters from the config.ini file my $cfg = new Config::Simple(); $cfg->read('config.ini'); my $host = $cfg->param("pbx"); my $port = $cfg->param("port"); print "Connecting to the PBX $host on port $port\n"; my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port,P +roto => "tcp",) or die "Cannot connect to PBX at address: $host port: $port: $!"; while (<$sock>) { s/^\0+//; # Remove leading null characters print $_; chomp ($_); #$_ =~ s/^[^ ]+//; if ($_ =~m"/") { &TXTout; &DBconnect; } } #Close While loop sub TXTout { my ($year, $mon, $day); $year = strftime '%Y', localtime; $mon = substr ($_, 1,2); $day = substr ($_, 4,2); my $file = "$year"."-"."$mon"."-"."$day".".log"; if (-f $file){ open (my $fh,'>>', $file); print $fh "$_\n"; close $file; } else { open (my $fh,'>', $file); print $fh "$_\n"; close $file; } }# End of filePrint routine sub DBconnect { # MySQL Connection parameters # MySQL Connection parameters my $dbuser= "user"; my $dbpassword= "password"; my $dbhost= "host"; my ($line, $mon, $day, $stime, $pm, $hrs, $mins, $sec, $callp, $leaddi +git, $callno, $speed, $callp2, $transf, $acccode, $sysid, $tester); $mon = substr ($_, 1,2); $day = substr ($_, 4,2); $stime = substr($_, 7,5); $pm = substr($_, 12,1); $hrs = substr($_, 14,2); $mins = substr($_, 17,2); $sec = substr($_, 20,2); $callp = substr($_, 23,4); $leaddigit = substr($_, 29,3); $callno = substr($_, 33,26); $speed = substr($_, 60,1); $callp2 = substr($_, 61,5); $transf = substr($_, 67,5); $acccode = substr($_, 72,12); $sysid = substr($_, 85,3); $tester = strftime( "%Y",localtime(time)); if ($acccode == ""){$acccode = 0} # Establish the connection which returns a DB handle my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) + or die $DBI::errstr; # Prepare the SQL statement my $stmt1 = qq(INSERT INTO import (month,day,time,PM,hrs,mins,sec,call +ingparty,leaddigit,calledno,speeddialind,calledparty,transferext,acco +untcode,sysid,year) VALUES('$mon','$day','$stime','$pm','$hrs','$mins +','$sec','$callp','$leaddigit','$callno','$speed','$callp2','$transf' +,'$acccode','$sysid','$tester');") or die $DBI::errstr; # Send the statement to the server my $rv1 = $dbh->do($stmt1) or die $DBI::errstr; # Close the database connection $dbh->disconnect or die $DBI::errstr; } #Close DBconnect subroutine #close the socket close $sock or die "close: $!"; print "socket closed"; print "<br />"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Include" parameters from website
by 1nickt (Canon) on Mar 15, 2021 at 18:19 UTC | |
by Polyglot (Chaplain) on Mar 16, 2021 at 02:21 UTC | |
by bajangerry (Sexton) on Mar 16, 2021 at 14:17 UTC | |
by marto (Cardinal) on Mar 16, 2021 at 15:38 UTC | |
by bajangerry (Sexton) on Mar 16, 2021 at 15:57 UTC | |
by bajangerry (Sexton) on Mar 15, 2021 at 18:41 UTC |