#!/bin/sh
# Copyright October 1998 by CyberSoft, Inc.
# this script will scan a tape device using dd and vfind
# the script can and most likely should be modified for use on your
# system.
#

if [ -z "${VSTK_HOME}" ]; then
    echo $0: "Please set the environment variable VSTK_HOME to the location of the VSTK directory"
    echo "\tfor example:  VSTK_HOME=/usr/local/VSTK"
    echo
    exit 1
fi

# Customise the script here
# by setting the VDL, TARGET. BLOCKSIZE, LOGFILE, and TMPFILE variables
# to the values that suit your needs.
VDL=${VSTK_HOME}/vdl/cyber07.vdl
export VDL

TARGET=/dev/rmt/0mn
export TARGET

BLOCKSIZE=20b
export BLOCKSIZE

TMPFILE=/tmp/scantape`date %d-%h-%Y`.tmp
export TMPFILE

LOGFILE=/tmp/scantape`date %d-%h-%Y`.log
export LOGFILE

echo "Rewinding ${TARGET}...."
mt -f ${TARGET} rew
echo

# mydd wraps the dd command to make the while loop prettier
mydd ()
{
   dd if=${TARGET} bs=${BLOCKSIZE} 2>/dev/null > ${TMPFILE} 
   return $? 
}

echo "########################################################" >> ${LOGFILE}
echo "SCAN OF $TARGET ON `date`" >> ${LOGFILE}
echo "########################################################" >> ${LOGFILE}
echo >> ${LOGFILE}

while mydd; do
   echo 
   echo "########################################################" | \
   tee -a ${LOGFILE}
   echo "SCANNING NEXT ITEM ON DEVICE ${TARGET}" | \
   tee -a ${LOGFILE}
   echo "########################################################" | \
   tee -a ${LOGFILE}
   echo | tee -a ${LOGFILE}
   cat ${TMPFILE} | \
   ${VSTK_HOME}/bin/vfind -quiet=2 ${VDL} -stdin | \
   grep '##==>>>>' 2>&1 | tee -a ${LOGFILE}
   rm -f ${TMPFILE}
done

rm -f ${TMPFILE}
echo | tee -a ${LOGFILE}
echo "########################################################" | \
tee -a ${LOGFILE}
echo "Scan Complete." | \
tee -a ${LOGFILE}
echo "########################################################" | \
tee -a ${LOGFILE}
echo "Please view ${LOGFILE} for details"
echo
echo "Rewinding ${TARGET}...."
mt -f ${TARGET} rew
exit 0

