moth/packages/octopus/solution.sh

16 lines
378 B
Bash
Raw Normal View History

2010-09-26 21:56:51 -06:00
#! /bin/sh
port=8888
2011-03-15 17:09:43 -06:00
host=${1:-10.0.0.8}
2010-09-26 21:56:51 -06:00
blooper=$(tempfile)
trap "rm $blooper" 0
2011-03-03 20:46:50 -07:00
echo foo | socat -t 0.01 STDIO UDP:$host:$port | tail -n +5 > $blooper
2010-09-26 21:56:51 -06:00
for i in $(seq 8); do
2010-10-22 11:15:37 -06:00
result=$(socat -t 0.01 STDIO UDP:$host:$port < $blooper | awk -F': ' '(NF > 1) {print $2; exit;}')
2010-09-26 21:56:51 -06:00
port=$(echo "ibase=8; $result" | bc)
2011-03-03 20:46:50 -07:00
echo "next port: $port ($result)"
2010-09-26 21:56:51 -06:00
done
echo $result