On Sun, 23 Jun 2002 02:16:03 +0200
Oliver Ob <[EMAIL PROTECTED]> wrote:

> Well why not exchange some scripts?
> I am new to that, too (got Zyxel 1496e+)
> 

#!/bin/perl -w

#       Monitor callerid

use Carp;
use strict;

use Device::SerialPort 0.06;
my $port = "/dev/modem";

my $PortObj;
$PortObj = Device::SerialPort->new ($port) or die "Can't start $port\n";

$PortObj->baudrate(9600);
$PortObj->parity("odd");
$PortObj->databits(8);
$PortObj->stopbits(1);
$PortObj->parity_enable(0);

$PortObj->handshake("dtr");

my $print = 0;
if (defined @ARGV && $ARGV[0] eq '-p') {$print = 1;}

my $gotit = "";
my @gotit;
my $count_in;
my $sleep = 1;

my $logfile = '/home2/archive/callerid/log';
my $archive = '/home2/archive/callerid/archive';

$SIG{'USR1'} = sub {$PortObj->write("ATZ\r"); sleep 3; die "usr1 kill signal 
recieved\n";};

#       Initialize modem

print "------- Starting Callerid ---------\n";

sleep 1;
$PortObj->write("ATZ\r");
sleep 1;
$PortObj->write("ATE1 S0=0 V1Q0#CID=1\r");

#---------------- main read loop ------------------
while (1) {
        ($count_in, $gotit) = $PortObj->read(500);
        sleep $sleep;
        next if $count_in == 0;
        &process;
        ($count_in, $gotit) = $PortObj->read(500);
        sleep 1;
        &process;
}
#---------------- end main read loop --------------

sub process {
        my @t = localtime(time); 
        my $datetime = ($t[5]+1900) . "-" . ($t[4]+1) . "-" . $t[3] . " " . $t[2] . 
":" . $t[1] . ":" . $t[0];
        $gotit =~ s/\r//g;

        open (ARCHIVE,">>$archive") || die "Can't open $archive, $!\n";
        print ARCHIVE "$gotit";
        close ARCHIVE;
}

=head1

kill -SIGUSR1 pid : this will flush the buffer and exit the program

Set the sticky bit so this will run as other than root....

chown root callerid.pl
chmod u+s callerid.pl

Alan Jackson, Copyright 2000, released under the same conditions as perl.
[EMAIL PROTECTED]

=cut

-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| [EMAIL PROTECTED]          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------
_______________________________________________
Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users
Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.

Reply via email to