#!/bin/bash -e
usage="rr-cntl cmd

Enable or disable updates on rr and associated servers.  This is done
by adding or removing the approriate crontabs.

cmd is start or stop
"

if [ $# != 1 ] ; then
    echo "wrong # args: $usage" >&2
    exit 1
fi
cmd=$1

case "$cmd" in
    start);;
    stop);;
    *)
    echo "invalid argument: \"$cmd\", expected \"start\" or \"stop\"" >&2
    exit 1 ;;
esac

sshCronTab() {
    local request=$1
    shift
    local host=$1
    shift
    local ctargs=$*
    echo $request $host
    ssh -x $host crontab $ctargs < /dev/null
}

case "$cmd" in
    start)
        sshCronTab start hgnfs1 /genbank/etc/hgnfs1.crontab
        sshCronTab start hgdownload /genbank/etc/hgdownload.crontab

    ;;

    stop)
        sshCronTab stop hgnfs1 -r
        sshCronTab stop hgdownload -r
    ;;
esac
