#! /bin/sh
# Autor: N.Pieroth, Erstellung: 01.12.99
# Extrahiert in einer Schleife alle Archive von einem Band.
# Sollte nach dem Lesen des letzten Archivs die
# Schleife beenden.
# Als Argument sollte der Devicename uebergeben werden. 
# The defaultargument is /dev/nrtape!

DEVICE="/dev/nrtape"
# Only available with "-h"-option set
USAGE="Usage: `basename $0` [-d devicename (/dev/rmt/tps0d4nrv)]"

while getopts hd: c
do
	case $c in 
	d)	DEVICE=$OPTARG;;
	h)	echo $USAGE
		exit 22;;
	esac
done

echo "###################################"
echo "# Rewind the tape                 #"
echo "###################################"
mt -f $DEVICE rewind

while :
do
	tar tvf $DEVICE 2>&-
	# Check the exitstatus of the previous tar-command
	if [ $? -ne 0 ]; then
            echo "###################################"
            echo "# No more archives on tape        #"
            echo "###################################"
	    exit 22
        fi
	# Change position to the begin of the next archive on tape
	mt -f $DEVICE fsf
done


mt -f $DEVICE rewind








