#!/bin/bash
# This script is to interacts with the streamfilter perl script
# It expects at least two arguments: the keyword to filter on (a perl regexp)
# and the command to execute (in the background) when the keyword occurs
# any additional arugments are treated as arguments to the command to execute
# any additional arguments that are "$count" will be replaces with how many
# times that pattern has matched previously ($count is one for the first match)
#
# reqparam value Pattern to match (perl regular expression)
# reqparam value Command to execute when Pattern occurs
# optparam value repeat Arguments to the command ($count is replaced with the number of matches)
#

. /etc/autobench.conf || . functions

if [ $# -lt 2 ]; then
  echo "watchfor $@: not enough arguments" >&2
  exit 1
fi

# put quotes around $1, and escape any "'s in it.
PATTERN=`echo $1 | sed -e 's:":\\":'`
echo WATCH_FOR MAGICWORD_DEADBEEFC001 \"$PATTERN\" ${@:2}
