#!/bin/ksh
# $Id: lastsbp.ksh,v 2.0 2004/01/11 20:47:39 ksb Exp $
#
# $Check(*): ${ssh-ssh-x} root@%s sh < %f
# Report the last time we ran an sbp, and the last time our host booted.

. /usr/local/lib/distrib/local.defs
PATH=$PATH:/etc
PROGNAME=`basename $0 .ksh`
BACKUP="`sbp -V | sed -ne 's,sbp: backup mount point: \(.*\),\1,p'`"
FSTAB="`sbp -V | sed -ne 's,sbp: list: \(.*\),\1,p'`"
BOOT="`labd -V | sed -ne 's,labd: boottime reported as[: ]*\(.*\),\1,p'`"

if [ "$1" = "-V" ]; then
	echo "$PROGNAME: "'$Id'
	exit
fi

# see if we can find a saner $BACKUP
if [ ! -d "$BACKUP" ] && [ -d "/alt" ]; then
	BACKUP=/alt
fi

# if we're not mounted, make sure to do it.
UMOUNT=false
if [ ! -f "$BACKUP/$FSTAB" ]; then
	UMOUNT=true
	mount $BACKUP || exit 2	# mount gives us the error
fi

# is /backup empty?
if [ ! -f "$BACKUP/$FSTAB" ]; then
	LAST=never
else
	LAST=`/usr/local/bin/stat -1 $BACKUP/$FSTAB | sed -ne 's,^Modify: \(.*\)(.*,\1,p'`
fi

if $UMOUNT; then
	umount $BACKUP
fi

echo "Last SBP:	$LAST"
echo "Last boot:	$BOOT"

exit 0
