2 ########################## tapeunload ###########################
3 # This script uses mtx 1.2.9pre2 to unload a tape
4 # based on its volume tag. You can
5 # specify a slot into which the tape should go, but if you don`t, it puts the
6 # tape into the slot from which it was taken. This slot number
8 # both from the standard output and as the exit value.
9 # A negative exit value indicates an error.
10 # If volume tags are missing from any full slot or drive,
11 # bar codes are rescanned automatically.
12 # Note: This script assumes that the tape is ready to be removed from
13 # the drive. That means you may have to unload the tape from the drive
14 # with "mt offline" before the tape can be moved to a storage slot.
18 # tapeunload TAPE_LABEL_1
19 # Removes tape with label TAPE_LABEL_1 from a drive and puts it
20 # back into its storage slot. Or,
21 # tapeunload TAPE_LABEL_1 40
22 # Removes tape with label TAPE_LABEL_1 from a drive and puts it
23 # into its storage slot 40.
26 # Set this variable to your mtx binary and proper scsi library device.
27 $MTXBIN="/usr/local/bin/mtx -f /dev/sga" ;
29 # Additions and corrections are welcome.
30 # This software comes with absolutely no warranty and every other imaginable
32 # -- Frank Samuelson sam@milagro.lanl.gov
34 ##################################################################
36 @wt= &mdo("status"); #slurp in the list of slots
38 # Check to be certain that every full slot has a volume tag
39 # Rescanning probably will not help. I haven`t seen any bar code
40 # readers that read tapes that are in the drives. But you never know...
41 for ($i=0; $i< $#wt; $i++) { # look through every line
42 if ( $wt[$i] =~ /Full/ && $wt[$i] !~ /VolumeTag/ ) {
43 # if the element is full, but there is no volume tag, do inventory
44 @wt= &mdo("inventory status");
51 for ($i=0; $i< $#wt; $i++) { # look through every line
52 # for a full tape drive
53 if ($wt[$i] =~ / *Data Transfer Element (d*):Full (Storage Element
54 (d*) Loaded):VolumeTag = (.*)/ ){
55 if ($ARGV[0] eq $3) { # We found our tape
56 $drivein=$1; # set the drive number
57 $slottogo=$2; # set the slot number
58 break; # stop reading the rest of the file.
63 if ( $drivein>=0) { # we found the tape you wanted.
64 if ($#ARGV==1) { #If an alternative slot was requested, set it.
65 $slottogo=$ARGV[1]; # and let mtx handle the errors.
68 # Now we unload the tape.
69 @dump=&mdo(" unload $slottogo $drivein ");
76 print STDERR " Ug. Tape $ARGV[0] is not in a tape drive.";
82 sub mdo # a subroutine to call mtx ;
84 # print STDERR "$_[0]";
85 if (!open(FD,"$MTXBIN $_[0] |")) { #call mtx function
86 print STDERR " ERRKK. Could not start mtx ";
90 @twt= <FD>; # slurp in the output
92 if (! close(FD)) { # if mtx exited with a nonzero value...
93 print STDERR " Mtx gave an error. Tapeload is exiting... ";