#!/bin/csh -f
#
# gathers volatile data from server into AFS
#
# mhpower, 16 November 1994,
#          (updated 21 April 1999; 29 May 2000; 16 August 2000)
# arolfe updated 1/2008 for new hardware/OS

setenv LOGNAME root
setenv USER root

set thishost = `/bin/hostname | awk -F. '{print $1}'`
set email = anxiety-maintainers
set nightlydir = /afs/sipb/machine/${thishost}/backups
setenv KRBTKFILE /tmp/tkt_root.$$
setenv KRB5CCNAME /tmp/krb5cc_root.$$
/usr/bin/kinit -l 2h -k -t /etc/keytab host/${thishost}.mit.edu
/usr/bin/aklog -cell sipb.mit.edu
/usr/bin/kdestroy

touch ${nightlydir}/afs_access_test
if ($status) then
	set quotainfo = `/usr/bin/fs listquota ${nightlydir} | sed -n 2p`
	set aclinfo = `/usr/bin/fs listacl ${nightlydir} | grep rcmd.${thishost}`

	/usr/sbin/sendmail -t << END_OF_MESSAGE
From: root@${thishost}.mit.edu
To: ${email}@mit.edu
Reply-To: ${email}@mit.edu
Subject: ${thishost} backup-to-afs failed

The backup-to-afs cron job on ${thishost} could not access the archive
directory ${nightlydir} this morning.

  % fs listquota ${nightlydir} | sed -n 2p
  ${quotainfo}
  % fs listacl ${nightlydir} | grep rcmd.${thishost}
  ${aclinfo}

--cron(8) on ${thishost}
END_OF_MESSAGE

	/usr/bin/unlog
	exit 1
endif

rm -f ${nightlydir}/afs_access_test
/bin/tar -c -f ${nightlydir}/${thishost}-configs.tar -T ${nightlydir}/files.${thishost} -P 
/usr/bin/unlog
exit 0
