#!/bin/sh # # Count file marks on a tape. It can optionally position the tape # after the last mark so you can append to the end of it. # # Andy Welter # www.the-welters.com # USAGE="mtfcount [-f ] [-append|-a]" if [ "$TAPE" = "" ]; then DEV=/dev/rmt/0n else DEV=$TAPE fi while [ $# -ge 1 ]; do case $1 in -f) DEV=$2 shift 2 ;; -append|-a) APPEND=yes shift ;; *) echo "$USAGE" exit 1 ;; esac done mt -f $DEV rewind COUNT=0 RC=0 while [ $RC -eq 0 ]; do echo "Skipping file $COUNT..." mt -f $DEV fsf 1 RC=$? if [ $RC -eq 0 ]; then COUNT=`expr $COUNT + 1` fi done echo "$COUNT files found on tape" echo "rewinding tape..." mt -f $DEV rewind if [ "$APPEND" = "yes" ]; then if [ $COUNT -ge 1 ]; then echo "positioning tape to the end..." mt -f $DEV fsf $COUNT fi fi