# Usage . bindWorkerVars.sh name
# (Re)init worker environment vars
name=$1
f=$HOME/.parallel/$name
rm -f $f
az vmss list-instance-connection-info -g cc -n $name | tr -s ',": ' '\t' | \
    tail -n +2 | fgrep instance |cut -f 4,5 | \
  while read ip port
   do
    echo ssh -p $port $ip >> $f
   done
ip=$(head -1 $f | cut -f 4 -d ' ')
export $name=$ip
export WORKERS=$name
sed '/export WORKERS/s/=.*$/='$name'/;/WORKERS names/s/ .*=[^ ]* / '$name'='$ip' /' -i $HOME/.bashrc
echo $name=$ip
