#!/bin/sh
#++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Script to check that the requested AO Server on the requested machine
#   is running
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Written  26jul07  DLM  Started with Phil Hinz's runao script
#
# Altered  13sep07  DLM  Added Topbox Server stuff
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# A server name must be supplied.  Check to see if one was sent
#
if [[ $1 == "" ]]; then
    echo "No server name given"
    echo "  usage:"
    echo "    query_process \"process_name\" \"machine_name\""
    echo "        \"process_name\" = pcr_server, pcr, dds, topbox_server"
    echo "        \"machine_name\" = ao-server.mmto.arizona.edu (for example)"
else
#
# Save the server name
#
    server=$1
#
# Check to see if a hostname was given.  If not, use "localhost"
#
    if [[ $2 != "" ]]; then
	hostname=$2
    else
	hostname="localhost"
    fi
#
# Must add mmtao user if trying to query a process on ao-server
#
    if [[ $hostname == ao-server.mmto.arizona.edu ]]; then
	hostname="mmtao@ao-server.mmto.arizona.edu"
    fi
#
# add username pcr
#
    if [[ $hostname == ao-pcr.mmto.arizona.edu ]]; then
#
# Special setup for pcr and dds running on ao-pcr
#
	hostname="mmtao@ao-pcr.mmto.arizona.edu"

	if [[ $server == pcr ]]; then
	    ssh -XYCq $hostname query_pcr_ao-pcr
	elif [[ $server == dds ]]; then
	    ssh -XYCq $hostname query_dds_ao-pcr
	else
	    echo "Unkown server $server"
	fi

    else
#
# All pcr_server and topbox_servers hosts will be the same.
#
# All other pcr and dds hosts will be running test routines (with the names
#   cmd, wfsc, error and dm)
#
	if [[ $server == pcr_server ]]; then
	    ssh -XYCq $hostname query_pcr_server
	elif [[ $server == pcr ]]; then
	    ssh -XYCq $hostname query_pcr_ao-pcr
	elif [[ $server == dds ]]; then
	    ssh -XYCq $hostname query_dds_ao-pcr
	elif [[ $server == topbox_server ]]; then
	    ssh -XYCq $hostname query_topbox_server
	elif [[ $server == science_server ]]; then
	    ssh -XYCq $hostname query_science_server
	    #query_science_server DEBUG
	elif [[ $server == tss_server ]]; then
	    ssh -XYCq $hostname query_tss_server
	else
	    echo "Unkown server $server"
	fi
    fi
fi
