#!/bin/perl -w # Monitor callerid BEGIN {push @INC, "/home/ajackson/bin/lib"} use Carp; use strict; use Device::SerialPort 0.06; my $port = "/dev/ttyS2"; 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 = '/archive/callerid/log'; my $archive = '/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; # print "---> $count_in : $gotit<---\n"; &process; ($count_in, $gotit) = $PortObj->read(500); sleep 1; # print "---> $count_in : $gotit<---\n"; &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]; open (ARCHIVE,">>$archive") || die "Can't open $archive, $!\n"; #print ARCHIVE "## $datetime : $gotit\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. callerid@ajackson.org =cut