#!/bin/bash
# gpssmswatch (c) 2004 Fritz Ganter <ganter@ganter.at>
# $Log: gpssmswatch,v $
# Revision 1.6  2004/01/15 22:46:23  ganter
# ...
#
# Revision 1.5  2004/01/15 21:18:51  ganter
# changed SECONDS to SECS
#
# Revision 1.4  2004/01/15 21:09:20  ganter
# added warning about deleting SMS from phone
#
# Revision 1.3  2004/01/15 16:48:32  ganter
# added log entry
#

SECS=30
echo -e ""
echo -e "gpssmswatch\n"
echo -e "polls every $SECS seconds the mobile phone and send position to the"
echo -e "number which sent a SMS with the text: PLSSENDPOS"
echo -e "This program requires a working gnokii\n"
echo -e "================================================"
echo -e "WARNING  WARNING WARNING WARNING WARNING WARNING\n"
echo -e "This program will DELETE all your incoming SMS"
echo -e "If you don't want this, stop program with CTRL-C now\n"
echo -e "WARNING  WARNING WARNING WARNING WARNING WARNING"
echo -e "================================================"
sleep 10

FILE=/tmp/.smswatch
while [ 1 = 1 ]
do
gnokii --getsms SM 1 > $FILE
if [ $? = "0" ];then
gnokii --deletesms SM 1
fi
grep PLSSENDPOS $FILE
if [ $? = "0" ];then
echo -e "position request found\n"
NUMBER=`grep Sender /tmp/.smswatch|awk '{print $2}'`
killall -USR1 gpsdrive

echo "sending "
cat /tmp/gpsdrivepos
echo -e "to number $NUMBER\n"
gnokii --sendsms $NUMBER < /tmp/gpsdrivepos
else
echo -e "no request\n"
fi
echo -e "Sleeping $SECS seconds"
sleep $SECS

done

 
