Главная страница


ru.perl

 
 - RU.PERL ----------------------------------------------------------------------
 From : Dmitriy Kyrhlarov                    2:5020/400     01 Oct 2002  15:32:47
 To : Eugene Grosbein
 Subject : Re: perl + COM-port + ATC
 -------------------------------------------------------------------------------- 
 
 Hi!
 
 Eugene Grosbein wrote:
 
 > 
 > Hе надо демона. Hе надо с COM-портом. Hадо так:
 
 У меня работает так:
 
 > cat /etc/rc.local && cat /usr/atslog/atslog.sh
 
 #!/bin/sh
 
 /usr/atslog/atslog.sh &
 
 #!/bin/sh
 
 while :
 do
 /usr/atslog/atslog.pl
 sleep 1
 done
 
 > cat /usr/atslog/atslog.pl
 
 #!/usr/bin/perl
 
 use DBI;
 
 #-##-#
 #$log = "-";
 $log = "/dev/cuaa1";
 $host = "dbhost";
 $db = "base";
 $user = "user";
 $password = "pass";
 #-##-#
 
 open (LOG, "<$log") || die "File $log not found!";
 $year = substr(localtime, -4);
 
 ### DB CONNECT ###
 
 $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $password) or die
 "Error connect to database with string: $db:$host";
 
 ### end DB CONNECT ###
 while (<LOG>)
   {
 # Trim start spaces
     $string = (s/^\s+//, $_);
 # Trim error strings and put data to the array
     if ($string !~ m/===|SMDR|DIAL NUMBER/ && $string =~ m/\d+/) {
       @array = split /\s+/, $string;
       $date = $array[2];
       $date =~ s/\D/-/;
       $time = $array[3];
       $SQL = "INSERT INTO incoming
 (stn,co,start_dt,duration,number,acc_code) VALUES (";
       for (0..1) {$SQL .= "'$array[$_]',"};
 # The DB field not identical of the field in raw log
       $SQL .= "'$year-$date $time'";
       for (4..6) {$SQL .= ",'$array[$_]'"};
       $SQL .= ")\n";
       $sth = $dbh->prepare($SQL) or die "Can't prepare $SQL";
       $sth->execute or die "Can't execute $sth->errstr";
       $sth->finish;
       #print $SQL;
     }
   }
 $rc = $dbh->disconnect;
 
 close (LOG);
 
 2EG. Плз, объясни, почему работать с STDIN предпочтительней.
 
 By.
 Dmitriy
 --- ifmail v.2.15dev5
  * Origin: Demos online service (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Re: perl + COM-port + ATC   Dmitriy Kyrhlarov   01 Oct 2002 15:32:47 
 perl + COM-port + ATC   Alan Long   02 Oct 2002 01:02:02 
Архивное /ru.perl/8054a8b46691.html, оценка 1 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional