#!/bin/sh
# we have to be root to run this
user=`id -u`
if [ ! $user -eq 0 ]; 
then 
    echo "You must be root to run this"
else
    # general setup
    cdir="cronBackup"
    cd
    rm -rf $cdir
    mkdir $cdir
    cd $cdir

    # copy over all of the HISTOGRAM files from the remote nodes
    for farmlet in `cat /usr/local/etc/farmlets/d0en /usr/local/etc/farmlets/stken`; 
    do 
	echo "Copying HISTOGRAM files from $farmlet"
	mkdir $farmlet
	cd $farmlet
	enrcp root@$farmlet:/root/CRON/*HISTOGRAM . 2> /dev/null 
	enrcp root@$farmlet:/home/enstore/CRON/*HISTOGRAM . 2> /dev/null
	cd ..
    done
    now=`date +%Y-%m-%d_%H-%M-%S`
    tname=cronHistograms_$now.tar
    echo "Making the gzipped tar file"
    tar -cf ../$tname *
    cd ..
    gzip $tname
    echo "Copying the gzipped tar file to tape"
fi

# now the gzipped file must be copied to tape on /pnfs/eagle/cron-backups.
# do this as user enstore
#
#    encp $tname.gz /pnfs/eagle/cron-backups
#
