#! /bin/sh

. "`dirname $0`/rcdefs"

case "$1" in
  start)
    if [ -n "${WORK}" ]
    then
      cd ${WORK}

      list=`echo *.check`

      if [ "$list" != "*.check" ]; then
      for checkfile in $list
      do
        job=`${BIN_CAT} $checkfile`
        Print -n "Starting background task $job... "
        name=`${BIN_BASENAME} $checkfile .check`
        PATH=.:$PATH nice -n 19 $job >> $name.out &
        Print "done."
      done
      fi
    fi
    ;;
  stop)
    if [ -n "${WORK}" ]
    then
      cd ${WORK}

      list=`echo *.check`

      if [ "$list" != "*.check" ]; then
      for checkfile in $list
      do
        name=`${BIN_BASENAME} $checkfile .check`
        Print -n "Stopping background task $name... "
        Terminate $name
        Print "done."
      done
      fi
    fi
    ;;
  *)
    Usage $0
    exit 1
esac

exit 0
