#!/bin/sh

test $# -eq 0 && { echo "usage: [number] [string]" 1>&2; exit 1; }

number=$1;
#string="$*";
string=$2;
dir="/home/plunkett/log/";
file="IrcLog.***";
logfile=$dir$file;
msgfile="/tmp/msg.$$";

while [ $# != 0 ]; do
  cat $logfile |grep -i "$string" > $msgfile;
  uniq $msgfile > /dev/null;
  numchars=`wc -c $msgfile|awk '{print $1}'`;
  if [ "$numchars" -lt "110" ]&&[ "$numchars" -gt "0" ]; then
    message=`cat $msgfile`;
    send="werdup! discussion on $string: $message";
    vodasms $number "$send";
  elif [ "$numchars" -gt "110" ]; then
    vodasms $number "they are talking way too much about $string ;)";
  fi;
  rm $msgfile;
  echo "" > $logfile;
  sleep 10s;
done; 
rm $logfile;  
