#!/bin/csh
#
#  first_last_8pak: Script to print the names of the first and last
#                   tar files on all tapes on a Peak 8pak autoloader.
#
#  Before running this script, all tapes should be unloaded.
#
#
set slots = (1 2 3 4 5 6 7 8)              # All slots in 8pak autoloader

mt -f /dev/rmt/0 offline >& /dev/null      # If a tape is loaded, unload
mtx -f /dev/changer unload >& /dev/null    # and eject it quietly

foreach s ($slots)
	mtx -f /dev/changer load $s        # Load tape from slot s
	if ($status != 0) continue;
	mt -f /dev/rmt/0 rewind            # Rewind tape
	echo -n "First file on tape "      # Print name of first file
	echo -n $s
	echo -n ": "
	tar tf /dev/rmt/0n
	mt -f /dev/rmt/0n eom              # Find beginning of last file
	mt -f /dev/rmt/0n nbsf 1
	echo -n "Last file on tape "       # Print name of last file
	echo -n $s
	echo -n ":  "
	tar tf /dev/rmt/0
	mt -f /dev/rmt/0 offline           # Eject the tape
	mtx -f /dev/changer unload         # Unload tape
end
