#!/bin/bash
#

trap 'echo "Stop that."' SIGINT

count=0
max=10

if [ x$1 != x ]; then
    max=$1
fi

echo "Number of gateways: $max"
fake=10
addr=17190

ttl=20
ttl_give=10
ept=gateway
pids=""

while [ $count -lt $max ]; do

    ./ept   --ttl $ttl \
            --ttl-give $ttl_give \
            --ept-type $ept \
            --address $addr \
            --ras-address 10.0.0.$fake:1719 \
            > /dev/null 2>>TOTALS &

    eval 'pids="$pids $!"'
    
    (( sleep = RANDOM % 10 )) 

    sleep $sleep
    
    (( ++fake ))
    (( ++addr ))
    
    (( ++count ))
done

echo $pids

trap "kill $pids" SIGINT

wait
