2 ########################## tapeload ###########################
3 # This script uses mtx 1.2.9pre2 to load a tape based
4 # on its volume tag. You can
5 # specify a tape drive by number, but if you don`t, it puts the
6 # tape in the first available drive and returns the number of that drive,
7 # both from the standard output and as the exit value.
8 # A negative exit value indicates an error.
9 # If volume tags are missing from any full slot, bar codes are rescanned
13 # tapeload TAPE_LABEL_1 # Loads tape with label TAPE_LABEL_1 into a drive
15 # tapeload TAPE_LABEL_1 1 # Loads tape with label TAPE_LABEL_1 into drive #1
18 # Set this variable to your mtx binary and proper scsi library device.
19 $MTXBIN="/usr/local/bin/mtx -f /dev/sga" ;
21 # Additions and corrections are welcome.
22 # This software comes with absolutely no warranty and every other imaginable
24 # -- Frank Samuelson sam@milagro.lanl.gov
25 ##################################################################
27 @wt= &mdo("status"); #slurp in the list of slots
29 # Check to be certain that every full slot has a volume tag
30 for ($i=0; $i< $#wt; $i++) { # look through every line
31 if ( $wt[$i] =~ /Full/ && $wt[$i] !~ /VolumeTag/ ) {
32 # if the element is full, but there is no volume tag, do inventory
33 @wt= &mdo("inventory status");
40 for ($i=0; $i< $#wt; $i++) { # look through every line
41 if ($wt[$i] =~ / *Storage Element (d*):Full :VolumeTag=(.*)/ ) {
42 if ($ARGV[0] eq $2) { # We found the tape
43 $slot=$1; # set the slot number
44 break; # stop reading the rest of the file.
49 if ( $slot>0) { # we found the tape you wanted.
51 $drivefound=-1; # set flag to bad value
52 for ($i=0; $i< $#wt; $i++) { # look through every line
53 # if this is a tape drive
54 if ($wt[$i] =~ / *Data Transfer Element (d*):(.*)/ ) { #parse the line
57 # print STDERR "$wt[$i] $drive $state";
58 if ($state =~ /Full/) { # This drive is full.
59 # if we are looking for a particular drive and this is it
60 if ( $#ARGV==1 && $drive == $ARGV[1]) {
61 print STDERR " ERROR: Specified drive $ARGV[1] is full.";
65 } elsif ($state =~ /Empty/) { #This is a tape drive and it`s empty.
66 if ( $#ARGV==1 ) { # If we want a particular drive
67 if ($drive == $ARGV[1]) { # and this is it,
68 $drivefound=$drive; # mark it so.
71 } else { # If any old drive will do
72 $drivefound=$drive; # Mark it.
75 } else { # This is a tape drive, but what the heck is it?
76 print STDERR " Cannot assess drive status in line";
83 if ( $drivefound < 0 ) { # specified drive was not found
84 print STDERR "Error: Specified drive $ARGV[1] was not found";
88 # Now we actually load the tape.
89 @dump=&mdo(" load $slot $drivefound ");
96 print STDERR " Ug. Tape $ARGV[0] is not in the library.";
102 sub mdo # a subroutine to call mtx ;
104 # print STDERR "$_[0]";
105 if (!open(FD,"$MTXBIN $_[0] |")) { #call mtx function
106 print STDERR " ERRKK. Could not start mtx ";
110 @twt= <FD>; # slurp in the output
112 if (! close(FD)) { # if mtx exited with a nonzero value...
113 print STDERR " Mtx gave an error. Tapeload is exiting... ";