#!/bin/sh

DIR='/usr/local/schools-noc/email-acceptance'


if [ "$1" = "" -o "$2" = "" -o "$3" != "" ]; then
 echo "Usage: $0 runs concurrency"
 exit 1;
fi

RUNS=$1
CONCURRENCY=$2

RUNCOUNTER=0
while [ $RUNCOUNTER -lt $RUNS ]; do
 sleep 10 &
 CCOUNTER=0
 while [ $CCOUNTER -lt $CONCURRENCY ]; do
  sleep 1
  CCOUNTER=$(($CCOUNTER + 1))
  perl $DIR/read-email.pl &
 done
 wait
 sleep 10 &
 CCOUNTER=0
 while [ $CCOUNTER -lt $CONCURRENCY ]; do
  sleep 1
  CCOUNTER=$(($CCOUNTER + 1))
  perl $DIR/send-email.pl &
 done
 wait
 sleep 10 &
 CCOUNTER=0
 while [ $CCOUNTER -lt $CONCURRENCY ]; do
  sleep 1
  CCOUNTER=$(($CCOUNTER + 1))
  perl $DIR/calendar.pl &
 done
 wait
 RUNCOUNTER=$(($RUNCOUNTER + 1))
done

