#!/bin/bash
[ "$1" == "" ] && exec echo "Usage: $0 <FastCGI Command>"

CGI_CMD=$1

IP=$(cat /etc/hosts | grep ' TIME1' | awk -F" " '{print $1}')
TOTAL_TEST_ZONE_INFO=$(ssh TEST "ls -hld ~/servers*/MissionServer*" | awk -F' ' '{print $NF}')
#echo "TOTAL_TEST_ZONE_INFO: ${TOTAL_TEST_ZONE_INFO}"

for ZONE_INFO in ${TOTAL_TEST_ZONE_INFO}; do
        ZONE=$(basename $(echo ${ZONE_INFO} | awk -F' ' '{print $NF}'))
        PORT=$(ssh TEST "cat ~/servers*/${ZONE}/setup.ini | grep 'CGIPort=' | sed 's/CGIPort=//'")
        #echo "Machine: TEST => IP: ${IP}, Server: ${ZONE}, Port: ${PORT}"
        echo "curl http://127.0.0.1/cgi-bin/CGIAgent.fcgi?${IP},${PORT},0KjaM85BjfqjA,${CGI_CMD}"
        curl http://127.0.0.1/cgi-bin/CGIAgent.fcgi?${IP},${PORT},0KjaM85BjfqjA,${CGI_CMD}
done
