AIT and DLT tape drives take longer to come on-line than the original
chg-*-mtx scripts expected. I have attached the version that I modified to
work with my QualStar that has a wait loop built in to get past this
problem.

        markh



-----Original Message-----
From: Jennifer Peterson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 17, 2002 8:04 AM
To: [EMAIL PROTECTED]
Subject: Re: ADIC Fastor DLT


Funny you should ask.  I'm currently working on this very system.  I'm 
using chg-zd-mtx with some success, but there's still some stuff I 
haven't been able to hammer out.  If anyone has any insight I would be 
much appreciative.

I was able to amlabel my tapes just fine, and "amtape baknon current" 
returns the label that I expect to see in the changer, and if I do an 
amcheck with the tape that amanda expects already in the changer, amanda 
reads the label and everything is fine.  However, if amanda needs to go 
out a retrieve tapes from the slots, either with amtape or with amcheck, 
it can't read the label once the tape gets to the changer.  I get
chg-zd-mtx:: no tape online.

Does anyone know why this would happen?

Thanks,

Jenn


-----
Message-ID: <[EMAIL PROTECTED]>
From: root <[EMAIL PROTECTED]>
To: Mark Holm <[EMAIL PROTECTED]>
Subject: chg-qs-mtx
Date: Thu, 17 Jan 2002 09:05:09 -0800
X-Mailer: Internet Mail Service (5.5.2650.21)

#!/bin/sh 
#
# Exit Status:
# 0 Alles Ok
# 1 Illegal Request
# 2 Fatal Error
#


# Setup path and
# try to hit all the possibilities here
prefix=/usr
exec_prefix=/usr
sbindir=/usr/sbin
libexecdir=/usr/lib/amanda
 

PATH=$sbindir:$libexecdir:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr
/ucb:/usr/local/bin
export PATH

#
# Check for debug log directory and setup to use it if available
#
if [ -d "/tmp/amanda" ]; then
        DBGFILE=/tmp/amanda/changer.debug
else
        DBGFILE=/dev/null
fi

USE_VERSION_SUFFIXES="no"
if test "$USE_VERSION_SUFFIXES" = "yes"; then
        SUF="-2.4.2p2"
else
        SUF=
fi

#
# Setup variables read from amanda.conf file
#
# Note! The tape dev defined below is the physical device i.e. /dev/nrst0
#       The changer dev is also the physical device for the robotics
typically
#         this is /dev/sg*
#
tape=`amgetconf$SUF tapedev`
TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command
if test "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" -o "$tape" = "" -o
"$TAPE" = ""; then
  echo "Both tapedev and changerdev must be specified in config file";
  exit 2;
fi

#
# Read in configuration paramters for this configuration. Thesesare defined
in
#  the file defined in changerfile with .conf appended. 
#
CHANGERCONF=`amgetconf$SUF changerfile`.conf
firstslot=`grep ^firstslot $CHANGERCONF | awk '{print $2}'`
endslot=`grep ^endslot $CHANGERCONF | awk '{print $2}'`
cleanslot=`grep ^cleanslot $CHANGERCONF | awk '{print $2}'`
cleancycle=`grep ^cleancycle $CHANGERCONF | awk '{print $2}'`
chgtapedev=`grep ^chgtapedev $CHANGERCONF | awk '{print $2}'`
needeject=`grep ^needeject $CHANGERCONF | awk '{print $2}'`

if test "$firstslot" = "/dev/null" -o "$firstslot" = ""; then
  echo "Changer definition of firstslot must be specified in the
$CHANGERCONF config file";
  exit 2;
fi

if test "$endslot" = "/dev/null" -o "$endslot" = ""; then
  echo "Changer definition of endslot must be specified in the $CHANGERCONF
config file";
  exit 2;
fi

if test "$cleanslot" = "/dev/null" -o "$cleanslot" = ""; then
  echo "Changer definition of cleanslot must be specified in the
$CHANGERCONF config file";
  exit 2;
fi

#
# This is the Transfer element number as defined by MTX. Typically 0 for the

#  first drive and 1 for the second
#
if test "$chgtapedev" = ""; then
  echo "chgtapedev must be specified in the $CHANGERCONF config file";
  exit 2;
fi

if test "$cleancycle" = "/dev/null" -o "$cleancycle" = ""; then
  cleancycle=10
fi

if test ! "$needeject" = "1"; then
  needeject=0
fi

echo "firstslot    -> $firstslot" >> $DBGFILE
echo "endslot      -> $endslot" >> $DBGFILE
echo "cleanslot    -> $cleanslot" >> $DBGFILE
echo "cleancycle   -> $cleancycle" >> $DBGFILE
echo "chgtapedev    -> $chgtapedev" >> $DBGFILE
echo "needeject    -> $needeject" >> $DBGFILE

changerfile=`amgetconf$SUF changerfile`
echo "changerfile     -> $changerfile" >> $DBGFILE
if [ "$changerfile" = "" ]; then
        changerfile=$HOME/changer
fi

cleanfile=$changerfile-clean${chgtapedev}
accessfile=$changerfile-access${chgtapedev}
[ ! -f $cleanfile ] && echo 0 > $cleanfile
[ ! -f $accessfile ] && echo 0 > $accessfile
cleancount=`cat $cleanfile`
accesscount=`cat $accessfile`
#

#
# Now that we have the basics defined set the system standards
# Modify these to fit your system
#
myname=$0
MT="/bin/mt"
MTF="-f"
MTX="mtx -f $TAPE"
DD=/bin/dd
maxwaittime=200

#
# Function definitions
#
eject_tape() {
    #
    # Check to see if we even need to do this
    if [ "$needeject" = "0" ]; then
        return
    fi
    res=`$MT $MTF $tape off 2>&1`
    status=$?
    if [ $status -ne 0  -a "$res" != "${tape}: No medium found" ];then
      echo "     -> eject_tape status $status" >> $DBGFILE
      echo "     -> eject_tape res    $res" >> $DBGFILE
      echo "     -> Drive Timed Out on eject" >> $DBGFILE

      #
      # Try it again - it sometimes frees up on two tries
      res=`$MT $MTF $tape off 2>&1`
      status=$?
      if [ $status -ne 0 ];then
        echo "     -> eject_tape 2 status $status" >> $DBGFILE
        echo "     -> eject_tape 2 res    $res" >> $DBGFILE
        echo "     -> Drive Timed Out again on eject" >> $DBGFILE
        echo "0 Drive timed out"
        exit 2
      fi
    fi
}

wait_for_tape() {
   time_remaining=$maxwaittime
   tape_online
   while [ $tape_ready = "FALSE" -a $time_remaining -gt 0 ]; do
      sleep 5
      time_remaining=$(( $time_remaining - 5 ))
      tape_online
   done

   if [ $time_remaining -le 0 ]; then
      echo "     -> Drive Timed Out" >> $DBGFILE
      echo "0 Drive timed out"
      exit 1
   fi
}


#

tape_online() {
   if [ `$MT $MTF $tape status | grep -ci online` -eq 1 ]; then
      echo "     -> Drive Ready" >> $DBGFILE
      tape_ready="TRUE"
   else
      echo "     -> Drive Not Ready" >> $DBGFILE
      tape_ready="FALSE"
   fi
}
         
#

readstatus() {
  used=`$MTX status |
    grep "Element ${chgtapedev}\:" |
    awk '/Full/ {print $7}; /Empty/ {print -1};'`

  if [ -z "$used" ]; then
    used="-1";
  fi
}


eject() {
  readstatus 
  if [ $used -gt 0 ];then
    eject_tape
    $MTX unload $used $chgtapedev > /dev/null 2>&1
    echo 0 $tape
    sleep 10
    exit 0
  else
    echo "0 Drive was not loaded"
    exit 1
  fi
}

reset() {
  readstatus
  if [ $used -gt 0 ];then
    eject_tape
    $MTX unload $used $chgtapedev > /dev/null 2>&1
  fi
  res=`$MTX load $firstslot $chgtapedev > /dev/null 2>&1`
  if [ $? -eq 0 ];then
    echo "1 $tape"
    wait_for_tape
    exit 0
  else
    echo "1 $res"
    exit 1
  fi
}
#
#
loadslot() {
  readstatus
  echo "     -> loaded $used" >> $DBGFILE
  whichslot=$1
  case $whichslot in
    current)
             if [ $used -lt 0 ];then
               eject_tape
               $MTX unload $used $chgtapedev > /dev/null 2>&1
               $MTX load $firstslot $chgtapedev > /dev/null 2>&1
               echo "$firstslot $tape"
               wait_for_tape
               exit 0
             else 
               echo "$used $tape"
               exit 0
             fi
             ;;
    next|advance)
          if [ $used -lt $firstslot ] ; then
              load=$firstslot
          else
              load=`expr $used + 1`
              if [ $load -gt $endslot ] ; then
                  load=$firstslot
              fi
          fi
          ;;
    prev)
          if [ $used -gt $endslot ] ; then
              load=$endslot
          else
              load=`expr $used - 1`
              if [ $load -lt $firstslot ] ; then
                 load=$endslot
              fi
          fi
          ;;
    first)
          load=$firstslot
          ;;
    last)
          load=$endslot
          ;;
    [1-9]*)
          if [ $firstslot -le $1 -a $1 -le $endslot ]; then
              load=$1
          else
              echo "0 Slot request out of range"
              exit 1
          fi
          ;;
    clean)
          load=$cleanslot
          ;;
    *)
       echo "0 illegal request"
       exit 1
       ;;
    esac

    if [ $load = $used ]; then
        echo "$used $tape"
        exit 0
    fi

    if [ $load = $cleanslot ]; then
        expr $cleancount + 1 > $cleanfile
        echo 0 > $accessfile
    else
        expr $accesscount + 1 > $accessfile
        if [ $accesscount -gt $cleancycle ]; then
                $myname -slot clean >/dev/null
        fi
    fi

    # Slot $cleanslot might contain an ordinary tape rather than a cleaning
    # tape. A cleaning tape auto-ejects; an ordinary tape does not.
    # We therefore have to read the status again to check what
    # actually happened.
    readstatus
        

    if [ $used -gt 0 ];then
      echo "     -> unload $used" >> $DBGFILE
      eject_tape
      res=`$MTX unload $used $chgtapedev >/dev/null 2>&1`
      status=$?
      echo "     -> status $status" >> $DBGFILE
      echo "     -> res    $res" >> $DBGFILE
      if [ $status -ne 0 ];then
        echo "$res"
        exit 2
      fi
    fi
    if [ $whichslot = advance ];then
      echo "$load /dev/null"
      exit 0
    fi
    echo "     -> load   $load" >> $DBGFILE
               
    res=`$MTX load $load $chgtapedev 2>&1`
    status=$?
    echo "     -> status $status" >> $DBGFILE
    echo "     -> res    $res" >> $DBGFILE
    if [ $status -ne 0 ];then
      #
      # One shot at stepping over an empty slot
      # If 2  in a row are empty it will fail
      #
      short_res=`echo $res | awk '{print $6 $7}'`
      if [ "${short_res}" = "isEmpty" ]; then

        case $whichslot in
        prev)
          load=`expr $load - 1`
          if [ $load -lt $firstslot ] ; then
             load=$endslot
          fi
          ;;
        next|addvance)
          load=`expr $load + 1`
          if [ $load -gt $endslot ] ; then
            load=$firstslot
          fi
          ;;
        esac

        res=`$MTX load $load $chgtapedev 2>&1`
        status=$?
      fi
      if [ $status -ne 0 ];then
        echo "$load $res"
        exit 2
      fi
    fi
    echo "     -> rew $load" >> $DBGFILE
    echo "$load $tape"
    wait_for_tape
    # $MT $MTF $tape rewind
    # $DD if=$tape count=1 >> $DBGFILE 2>&1
    # wait_for_tape
    exit 0
}
#
info() {
  readstatus
  echo "     -> info   $used" >> $DBGFILE
  if [ $used -lt 0 ];then
    echo "0 $endslot 1"
  else
    echo "$used $endslot 1"
  fi
  exit 0
}
#
echo Args "->" "$@" >> $DBGFILE
while [ $# -ge 1 ];do
  case $1 in
    -slot)
           shift
           loadslot $*
           ;;
    -info)
           shift
           info
           ;;
    -reset)
            shift
            reset
            ;;
    -eject)
            shift
            eject
            ;;
    *)
       echo "Unknown option $1"
       exit 2
       ;;
  esac
done

Reply via email to