#!/bin/bash -f
#------------------------------------------------------------------------------
# Script to check the status of Spectro-Robot.
#
# D. Schlegel, Princeton, 20 Dec 2000
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# If a second argument is give, such as "sprobot_status plate-mapper", or
# "sprobot_status observer@plate-mapper.apo.nmsu.edu", then run this command
# remotely on the machine "plate-mapper".

if [ $# = 1 ] ; then
  ssh $1 sprobot_status
  exit
fi

#------------------------------------------------------------------------------
# Test to see if the cron job is already loaded.

echo
vers=`crontab -l | awk 'BEGIN{begin = 0; end = 0}{if ($2 == "SPROBOT" && $3 == "BEGIN") {begin = 1; vers = $4}; if ($2 == "SPROBOT" && $3 == "END" && begin == 1) {end = 1}}END{if (begin == 1 && end == 1){print vers} else {print "0"}}'`
machine=`uname -n`
if [ $vers != "0" ] ; then
  echo "Spectro-Robot cron IS running for USER="$USER" MACHINE="$machine"."
  echo "Loaded version="$vers"."
else
  echo "The Spectro-Robot cron job is NOT running for USER="$USER" MACHINE="$machine"."
fi

#------------------------------------------------------------------------------
