#!/bin/bash NRUNS=${NRUNS:-4} XWORDS=${XWORDS:-"./obj_linux_memdbg/xwords"} DICT=${DICT:-dict.xwd} HOST=${HOST:-localhost} PORT=${PORT:-10999} QUIT=${QUIT:-"-q 2"} USE_CURSES=${USE_CURSES:="yes"} usage() { echo "usage: $0 " cat </dev/null | cksum | cut -f1 -d" ") # echo $RAND echo $RANDOM } do_one() { COOKIE=${1:-$(exec sh -c 'echo $PPID')} while :; do # loop forever (eventually) TODO=$(($COOKIE % 3)) TODO=$((TODO+2)) COUNT=0 for NAME in Bbbbb Aaaaa Kkkkk Eeeee; do [ $COUNT = $TODO ] && break while :; do RAND=$(random) INDEX=$(( $RAND % $TODO )) WAIT=$(( $RAND % 60 )) case $INDEX in 0) if [ -z "$ZERO_DONE" ]; then REMOTES="" for JJ in $(seq $(($TODO-1))); do REMOTES="$REMOTES -N"; done ZERO_DONE=1 echo $COOKIE:ZERO if [ "$USE_CURSES" = "yes" ]; then $XWORDS -d $DICT -r $NAME -s $REMOTES \ -a $HOST -p $PORT -C $COOKIE $QUIT -u \ -z 0:$WAIT >/dev/null \ 2>/tmp/log_${COOKIE}_${INDEX}.txt & else $XWORDS -d $DICT -r $NAME -s $REMOTES \ -a $HOST -p $PORT -C $COOKIE $QUIT & fi break fi ;; 1) if [ -z "$ONE_DONE" ]; then ONE_DONE=1 echo $COOKIE:ONE if [ "$USE_CURSES" = "yes" ]; then $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT -u \ -z 0:$WAIT >/dev/null \ 2>/tmp/log_$COOKIE_${INDEX}.txt & else $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT & fi break fi ;; 2) if [ -z "$TWO_DONE" ]; then TWO_DONE=1 echo $COOKIE:TWO if [ "$USE_CURSES" = "yes" ]; then $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT -u \ -z 0:$WAIT >/dev/null \ 2>/tmp/log_$COOKIE_${INDEX}.txt & else $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT & fi break fi ;; 3) if [ -z "$THREE_DONE" ]; then THREE_DONE=1 echo $COOKIE:THREE if [ "$USE_CURSES" = "yes" ]; then $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT -u \ -z 0:$WAIT >/dev/null \ 2>/tmp/log_$COOKIE_${INDEX}.txt & else $XWORDS -d $DICT -r $NAME -a $HOST -p $PORT \ -C $COOKIE $QUIT & fi break fi ;; esac done COUNT=$((COUNT+1)) done wait break done } ############################################################################ # main [ -n "$1" ] && usage for II in $(seq $NRUNS); do do_one $II & done wait