#! /bin/csh
# $Header: weeklymain,v 4.300 91/06/09 01:00:34 root Rel41 $
# Script to produce weekly statistics on NYSERNet nodes, and move files around
#
# Written 4/21/88 by Wengyik Yeong for the NYSERNet 
#
# Copyright 1990, Performance Systems International Inc.
# Copyright 1988,1989 NYSERNet Inc.
# Copyright 1990, Sony Corp.
# All Rights Reserved
#

source ../../config/report-env
if (-e $ROOT/config/weekly-env) then
  source $ROOT/config/weekly-env
else
  echo "$0 : weekly-env missing. Can't continue. Exit."
  exit(1)
endif

#set verbose
if ($#argv >= 1) then
        set	ext=$argv[1]
else
        echo "Usage: $0 mmddyy"
	exit(1)
endif

set crntdir = `pwd`
set workplace=/tmp/snmp.$ext
if (-e $workplace) then
  /bin/rm -rf $workplace
endif
mkdir $workplace

if (! $?WEEKLYREPORTS) then
  set file = $ROOT/weekly/report/weekly.$ext
else
  set file = $WEEKLYREPORTS/weekly.$ext
endif

if (-e $file) then
  /bin/rm -f $file
endif

$BIN/moverawdata $ext $workplace

set Date = `$BIN/prsdate $ext`
echo -n " SNMP Weekly Statistic Report for the week ended $Date        " > $file

$BIN/genweekly $ext >> ${file}

cd $workplace
/bin/rm -f *
chdir $crntdir
rmdir $workplace
 
# copy or move the reports as user requested
if ($?MVWEEKLYRPT && $?WEEKLYREPORTDIR) then
  mv $file $WEEKLYREPORTDIR
endif

if ($?CPWEEKLYRPT && $?WEEKLYREPORTDIR) then
  cp $file $WEEKLYREPORTDIR
endif

# inform the operater
if ($?OPERATER) then
  if ($?WEEKLYREPORTDIR) then
    set where=$WEEKLYREPORTDIR
  else
    set where=$file:h
  endif
    echo "weekly statistics data is in $where ." |\
            /usr/ucb/mail -s "weekly_statistics report on $HOST" $OPERATER 
endif

