#!/bin/bash
# Colin Parkes
# 15/10/2000
#
# This script monitors a comm port for any signals sent in (eg. cts, dsr)
# If detected, it dials a pager through the other comm port via a modem and
# sends 999, when clear it sends 666.
# I use it with a relay across pins 7 & 8 (RTS & CTS). The relay is triggered
# by the 12 volts from my burglar alarm (Most burglar alarms have a 12 volt
# hold off voltage which goes to the external bellbox, when the alarm is
# triggered, this drops.)
#
# Make sure you have the following UUCP files in place for CU to work..
# For Linux you should find sample scripts.
# cp /usr/doc/uucp-1.06.1/sample/* /etc/uucp/
# /etc/uucp/port : ( device = /dev/ttyS1)
# /etc/uucp/dial : ( check the dial string in case the modem is in quiet mode)
#
alarmdir=/var/log/alarmmon
statefile=comm1temp
logfile=alarmlog
#
while [ ! -d $alarmdir ]
do
mkdir $alarmdir
chmod 777 $alarmdir
done
while [ -z "`ps -ef | grep -v grep | grep statserial `" ]
do
statserial -d /dev/ttyS0 > $alarmdir/$statefile
if [ `cat $alarmdir/$statefile` -eq 16390 ]
then
echo "OK"
sleep 1
else
echo "Alarm" >> $alarmdir/$logfile
date >> $alarmdir/$logfile
cu -p port1 -c <pagernumber>,,,999,#
sleep 1
while [ `cat $alarmdir/$statefile` -ne 16390 ]
do
statserial -d /dev/ttyS0 > $alarmdir/$statefile
sleep 1
done
echo "Clear" >> $alarmdir/$logfile
date >> $alarmdir/$logfile
echo "" >> $alarmdir/$logfile
cu -p port1 -c <pagernumber>,,,666,#
fi
done