> Hi Joe, > > Could you send a patch (diff -u) for chg-zd-mtx.sh.in ? My diff doesn't understand "-u" as an option. I've attached a normal diff and a context diff between the original chg-zd-mtx.sh.in and my update. > Did the new script is compatible with the previous? It works perfectly as a drop-in replacement. It also - * fixes numerous bugs * skips empty slots * works with mtx.1.2.x * supports tape drives which autoclean * supports tape drives which require 'mt offline' before 'mtx unload' -- Joe Rhett Chief Technology Officer [EMAIL PROTECTED] ISite Services, Inc. PGP keys and contact information: http://www.noc.isite.net/Staff/
9a10,13 > # > # Modified by Joe Rhett <[EMAIL PROTECTED]> > # to work with MTX 1.2.9 by Eric Lee Green http://mtx.sourceforge.net > # 11c15,36 < # try to hit all the possibilities here --- > # You may need to customize these things > MT=@MT@ > MTF=@MT_FILE_FLAG@ > MTX=@MTX@ > firstslot=1 > lastslot=7 # Don't forget to leave out the cleaning tape. > cleanslot=8 # Which slot contains your cleaning tape? > > # Does your tape driver require a 'mt offline' before mtx unload? > OFFLINE_BEFORE_UNLOAD=0 > > # Do you want to clean the drive after a certain number of accesses? > # NOTE - This is unreliable, since 'accesses' aren't 'uses', and we > # have no reliable way to count this. A single amcheck could > # generate as many accesses as slots you have, plus 1. > # ALSO NOTE - many modern tape loaders handle this automatically. > # > AUTOCLEAN=0 # Set to '1' or greater to enable > autocleancount=99 > # No user-level customized required beyond this point. > > # Paths 16c41,42 < --- > > # try to hit all the possibilities here 37,38c63,64 < echo "Both tapedev and changerdev must be specified in config file"; < exit 2; --- > echo "Both tapedev and changerdev must be specified in config file"; > exit 2; 40,48d65 < fake=0 < MT=@MT@ < MTF=@MT_FILE_FLAG@ < MTX=@MTX@ < DD=@DD@ < firstslot=1 < lastslot=6 < # counted from 1 !!! < cleanslot=-2 60d76 < # 61a78 > # Routines start here 63,64c80,81 < used=`$MTX status | < sed -n 's/Data Transfer Element:.Empty/-1/p;s/Data Transfer Element:.Full (Storage Element \(.\) Loaded)/\1/p'` --- > usedslot=`$MTX status | > sed -n 's/Data Transfer Element 0:Empty/-1/p;s/Data Transfer Element >0:Full (Storage Element \(.\) Loaded)/\1/p'` 66,69c83,86 < if [ "$used" -eq -1 ]; then < used=`cat $slotfile` < fake=1 < fi --- > if [ "$usedslot" -eq "-1" ]; then > echo '-1' > $slotfile > fi > echo "STATUS -> currently loaded slot = $usedslot" >> $DBGFILE 74,82c91,103 < readstatus < if [ $used -gt 0 ];then < $MTX unload $used 2>/dev/null < echo 0 $tape < exit 0 < else < echo "0 Drive was not loaded" < exit 1 < fi --- > readstatus > echo "EJECT -> ejecting tape from slot $usedslot" >> $DBGFILE > if [ $usedslot -gt 0 ]; then > if [ $OFFLINE_BEFORE_UNLOAD -gt 0 ]; then > $MT $MTF $tape offline > fi > $MTX unload $usedslot 2>/dev/null > echo "0 $tape" > exit 0 > else > echo "0 Drive was not loaded" > exit 1 > fi 86,97c107,116 < readstatus < if [ $used -gt 0 ];then < $MTX unload $used 2>/dev/null < fi < res=`$MTX load 1 2>&1` < if [ $? -eq 0 ];then < echo "1 $tape" < exit 0 < else < echo "1 $res" < exit 1 < fi --- > $myname -eject >/dev/null > echo "RESET -> loading tape from slot 1" >> $DBGFILE > result=`$MTX load 1 2>&1` > if [ $? -eq 0 ]; then > echo "1 $tape" > exit 0 > else > echo "1 $result" > exit 1 > fi 99,100c118 < # < # --- > 102,140c120 < readstatus < echo " -> loaded $used" >> $DBGFILE < whichslot=$1 < case $whichslot in < current) < if [ $used -lt 0 ];then < $MTX load 1 2>/dev/null < echo "1 $tape" < exit 0 < else < echo "$used $tape" < exit 0 < fi < ;; < next|advance) < load=`expr $used + 1` < [ $load -gt $lastslot ] && load=$firstslot < ;; < prev) < load=`expr $used - 1` < [ $load -lt $firstslot ] && load=$lastslot < ;; < first) < load=$firstslot < ;; < last) < load=$lastslot < ;; < [$firstslot-$lastslot]) < load=$1 < ;; < clean) < load=$cleanslot < ;; < *) < echo "0 illegal request" < exit 1 < ;; < esac --- > readstatus 142,145c122,165 < if [ $load = $used ]; then < echo "$used $tape" < exit 0 < fi --- > whichslot=$1 > echo "LOADSLOT -> load tape from slot $whichslot" >> $DBGFILE > case $whichslot in > current) > if [ $usedslot -lt 0 ]; then > loadslot=$firstslot > else > echo "$usedslot $tape" > exit 0 > fi > ;; > next|advance) > if [ $usedslot -lt 0 ]; then > loadslot=$firstslot > else > loadslot=`expr $usedslot + 1` > if [ $loadslot -gt $lastslot ]; then > loadslot=$firstslot > fi > fi > ;; > prev) > loadslot=`expr $usedslot - 1` > if [ $loadslot -lt $firstslot ]; then > loadslot=$lastslot > fi > ;; > first) > loadslot=$firstslot > ;; > last) > loadslot=$lastslot > ;; > [${firstslot}-${lastslot}]) > loadslot=$1 > ;; > clean) > loadslot=$cleanslot > ;; > *) > echo "0 illegal request" > exit 1 > ;; > esac 147,153c167,170 < if [ $load = $cleanslot ]; then < expr $cleancount + 1 > $cleanfile < echo 0 > $accessfile < else < expr $accesscount + 1 > $accessfile < if [ $accesscount -gt 9 ]; then < $myname -slot clean >/dev/null --- > # Is this already the current slot? > if [ $loadslot = $usedslot ]; then > echo "$usedslot $tape" > exit 0 155d171 < fi 157,162c173,180 < # Slot 6 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 < --- > # Is this a cleaning request? > if [ $loadslot = $cleanslot ]; then > expr $cleancount + 1 > $cleanfile > echo 0 > $accessfile > else > expr $accesscount + 1 > $accessfile > if [ $AUTOCLEAN -gt 0 -a $accesscount -gt $autocleancount ]; then > $myname -slot clean >/dev/null 164,195c182,218 < if [ $fake -eq 0 ];then < echo " -> unload $used" >> $DBGFILE < res=`$MTX unload $used 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 2>&1` < status=$? < echo " -> status $status" >> $DBGFILE < echo " -> res $res" >> $DBGFILE < if [ $status -eq 0 ];then < echo " -> rew $load" >> $DBGFILE < $MT $MTF $tape rewind < $DD if=$tape count=1 >> $DBGFILE 2>&1 < echo "$load $tape" < echo "$load" > $slotfile < exit 0 < else < res2=`echo $res | grep "Storage Element . is Empty"` < if [ -z $res2 ]; then < echo "$load $res" < exit 2 --- > # Slot $cleanslot might contain an ordinary tape rather than a >cleaning > # tape. A cleaning tape *MIGHT* auto-eject; an ordinary tape >does not. > # We therefore have to read the status again to check what >actually happened. > readstatus > fi > fi > > # Unload any previous tape > if [ $usedslot -ne "-1" ]; then > echo " -> unload $usedslot" >> $DBGFILE > if [ $OFFLINE_BEFORE_UNLOAD -gt 0 ]; then > $MT $MTF $tape offline > fi > result=`$MTX unload $usedslot 2>&1` > status=$? > echo " -> status $status, result '$result'" >> $DBGFILE > if [ $status -ne 0 ]; then > echo "$loadslot $result" > exit 2 > fi > fi > > # Load the tape, finally! > echo " -> loading tape from slot $loadslot" >> $DBGFILE > result=`$MTX load $loadslot 2>&1` > status=$? > echo " -> status $status, result '$result'" >> $DBGFILE > > # If there is an error, abort unless the slot is simply empty > if [ $status -ne 0 ]; then > empty=`echo $result | grep "is Empty"` > if [ -z "$empty" ]; then > echo "$loadslot $result" > exit 2 > else > loadslot next > fi 197,199c220,233 < echo "$load $res" < echo "$load" > $slotfile < exit 1 --- > # Don't assume the drive is ready until we stop getting tape offline > readyError="offline" > while [ -n "$readyError" ]; do > readyStatus=`$MT $MTF $tape status 2>&1` > echo " -> readyStatus = $readyStatus" >> $DBGFILE > readyError=`echo $readyStatus | grep "offline"` > done > > # Now rewind and check > echo " -> rewind $loadslot" >> $DBGFILE > $MT $MTF $tape rewind > echo "$loadslot" > $slotfile > echo "$loadslot $tape" > exit 0 201d234 < fi 203c236 < # --- > 205,213c238,245 < readstatus < echo " -> info $used" >> $DBGFILE < if [ $used -lt 0 ];then < slot=`cat $slotfile` < echo "$slot $lastslot 1" < else < echo "$used $lastslot 1" < fi < exit 0 --- > readstatus > echo "INFO -> current slot $usedslot, last slot $lastslot, can go backwards 1" >>> $DBGFILE > if [ $usedslot -lt 0 ]; then > echo "0 $lastslot 1" > else > echo "$usedslot $lastslot 1" > fi > exit 0 215,216c247,249 < # < echo Args "->" "$@" >> $DBGFILE --- > > # Program invocation begins here > echo "\n`date` Invoked with args '$@'" >> $DBGFILE 218,239c251,272 < case $1 in < -slot) < shift < loadslot $* < ;; < -info) < shift < info < ;; < -reset) < shift < reset < ;; < -eject) < shift < eject < ;; < *) < echo "Unknown option $1" < exit 2 < ;; < esac --- > case $1 in > -slot) > shift > loadslot $* > ;; > -info) > shift > info > ;; > -reset) > shift > reset > ;; > -eject) > shift > eject > ;; > *) > echo "Unknown option $1" > exit 2 > ;; > esac
*** chg-zd-mtx.sh.in-orig Wed Sep 8 16:26:07 1999 --- chg-zd-mtx.sh.in Sat Jan 27 01:10:31 2001 *************** *** 7,19 **** # # Contributed by Eric DOUTRELEAU <[EMAIL PROTECTED]> # This is supposed to work with Zubkoff/Dandelion version of mtx ! # try to hit all the possibilities here prefix=@prefix@ exec_prefix=@exec_prefix@ sbindir=@sbindir@ libexecdir=@libexecdir@ ! PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin export PATH --- 7,45 ---- # # Contributed by Eric DOUTRELEAU <[EMAIL PROTECTED]> # This is supposed to work with Zubkoff/Dandelion version of mtx + # + # Modified by Joe Rhett <[EMAIL PROTECTED]> + # to work with MTX 1.2.9 by Eric Lee Green http://mtx.sourceforge.net + # ! # You may need to customize these things ! MT=@MT@ ! MTF=@MT_FILE_FLAG@ ! MTX=@MTX@ ! firstslot=1 ! lastslot=7 # Don't forget to leave out the cleaning tape. ! cleanslot=8 # Which slot contains your cleaning tape? ! ! # Does your tape driver require a 'mt offline' before mtx unload? ! OFFLINE_BEFORE_UNLOAD=0 ! ! # Do you want to clean the drive after a certain number of accesses? ! # NOTE - This is unreliable, since 'accesses' aren't 'uses', and we ! # have no reliable way to count this. A single amcheck could ! # generate as many accesses as slots you have, plus 1. ! # ALSO NOTE - many modern tape loaders handle this automatically. ! # ! AUTOCLEAN=0 # Set to '1' or greater to enable ! autocleancount=99 ! # No user-level customized required beyond this point. ! ! # Paths prefix=@prefix@ exec_prefix=@exec_prefix@ sbindir=@sbindir@ libexecdir=@libexecdir@ ! ! # try to hit all the possibilities here PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin export PATH *************** *** 34,51 **** tape=`amgetconf$SUF tapedev` TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then ! echo "Both tapedev and changerdev must be specified in config file"; ! exit 2; fi - fake=0 - MT=@MT@ - MTF=@MT_FILE_FLAG@ - MTX=@MTX@ - DD=@DD@ - firstslot=1 - lastslot=6 - # counted from 1 !!! - cleanslot=-2 changerfile=`amgetconf$SUF changerfile` --- 60,68 ---- tape=`amgetconf$SUF tapedev` TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then ! echo "Both tapedev and changerdev must be specified in config file"; ! exit 2; fi changerfile=`amgetconf$SUF changerfile` *************** *** 57,240 **** [ ! -f $slotfile ] && echo 0 > $slotfile cleancount=`cat $cleanfile` accesscount=`cat $accessfile` - # readstatus() { ! used=`$MTX status | ! sed -n 's/Data Transfer Element:.Empty/-1/p;s/Data Transfer Element:.Full (Storage Element \(.\) Loaded)/\1/p'` ! if [ "$used" -eq -1 ]; then ! used=`cat $slotfile` ! fake=1 ! fi } eject() { ! readstatus ! if [ $used -gt 0 ];then ! $MTX unload $used 2>/dev/null ! echo 0 $tape ! exit 0 ! else ! echo "0 Drive was not loaded" ! exit 1 ! fi } reset() { ! readstatus ! if [ $used -gt 0 ];then ! $MTX unload $used 2>/dev/null ! fi ! res=`$MTX load 1 2>&1` ! if [ $? -eq 0 ];then ! echo "1 $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 ! $MTX load 1 2>/dev/null ! echo "1 $tape" ! exit 0 ! else ! echo "$used $tape" ! exit 0 ! fi ! ;; ! next|advance) ! load=`expr $used + 1` ! [ $load -gt $lastslot ] && load=$firstslot ! ;; ! prev) ! load=`expr $used - 1` ! [ $load -lt $firstslot ] && load=$lastslot ! ;; ! first) ! load=$firstslot ! ;; ! last) ! load=$lastslot ! ;; ! [$firstslot-$lastslot]) ! load=$1 ! ;; ! 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 9 ]; then ! $myname -slot clean >/dev/null fi - fi ! # Slot 6 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 [ $fake -eq 0 ];then ! echo " -> unload $used" >> $DBGFILE ! res=`$MTX unload $used 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 2>&1` ! status=$? ! echo " -> status $status" >> $DBGFILE ! echo " -> res $res" >> $DBGFILE ! if [ $status -eq 0 ];then ! echo " -> rew $load" >> $DBGFILE ! $MT $MTF $tape rewind ! $DD if=$tape count=1 >> $DBGFILE 2>&1 ! echo "$load $tape" ! echo "$load" > $slotfile ! exit 0 ! else ! res2=`echo $res | grep "Storage Element . is Empty"` ! if [ -z $res2 ]; then ! echo "$load $res" ! exit 2 else ! echo "$load $res" ! echo "$load" > $slotfile ! exit 1 fi - fi } ! # info() { ! readstatus ! echo " -> info $used" >> $DBGFILE ! if [ $used -lt 0 ];then ! slot=`cat $slotfile` ! echo "$slot $lastslot 1" ! else ! echo "$used $lastslot 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 --- 74,273 ---- [ ! -f $slotfile ] && echo 0 > $slotfile cleancount=`cat $cleanfile` accesscount=`cat $accessfile` + # Routines start here readstatus() { ! usedslot=`$MTX status | ! sed -n 's/Data Transfer Element 0:Empty/-1/p;s/Data Transfer Element 0:Full (Storage Element \(.\) Loaded)/\1/p'` ! if [ "$usedslot" -eq "-1" ]; then ! echo '-1' > $slotfile ! fi ! echo "STATUS -> currently loaded slot = $usedslot" >> $DBGFILE } eject() { ! readstatus ! echo "EJECT -> ejecting tape from slot $usedslot" >> $DBGFILE ! if [ $usedslot -gt 0 ]; then ! if [ $OFFLINE_BEFORE_UNLOAD -gt 0 ]; then ! $MT $MTF $tape offline ! fi ! $MTX unload $usedslot 2>/dev/null ! echo "0 $tape" ! exit 0 ! else ! echo "0 Drive was not loaded" ! exit 1 ! fi } reset() { ! $myname -eject >/dev/null ! echo "RESET -> loading tape from slot 1" >> $DBGFILE ! result=`$MTX load 1 2>&1` ! if [ $? -eq 0 ]; then ! echo "1 $tape" ! exit 0 ! else ! echo "1 $result" ! exit 1 ! fi } ! loadslot() { ! readstatus ! whichslot=$1 ! echo "LOADSLOT -> load tape from slot $whichslot" >> $DBGFILE ! case $whichslot in ! current) ! if [ $usedslot -lt 0 ]; then ! loadslot=$firstslot ! else ! echo "$usedslot $tape" ! exit 0 ! fi ! ;; ! next|advance) ! if [ $usedslot -lt 0 ]; then ! loadslot=$firstslot ! else ! loadslot=`expr $usedslot + 1` ! if [ $loadslot -gt $lastslot ]; then ! loadslot=$firstslot ! fi ! fi ! ;; ! prev) ! loadslot=`expr $usedslot - 1` ! if [ $loadslot -lt $firstslot ]; then ! loadslot=$lastslot ! fi ! ;; ! first) ! loadslot=$firstslot ! ;; ! last) ! loadslot=$lastslot ! ;; ! [${firstslot}-${lastslot}]) ! loadslot=$1 ! ;; ! clean) ! loadslot=$cleanslot ! ;; ! *) ! echo "0 illegal request" ! exit 1 ! ;; ! esac ! # Is this already the current slot? ! if [ $loadslot = $usedslot ]; then ! echo "$usedslot $tape" ! exit 0 fi ! # Is this a cleaning request? ! if [ $loadslot = $cleanslot ]; then ! expr $cleancount + 1 > $cleanfile ! echo 0 > $accessfile ! else ! expr $accesscount + 1 > $accessfile ! if [ $AUTOCLEAN -gt 0 -a $accesscount -gt $autocleancount ]; then ! $myname -slot clean >/dev/null ! # Slot $cleanslot might contain an ordinary tape rather than a cleaning ! # tape. A cleaning tape *MIGHT* auto-eject; an ordinary tape does not. ! # We therefore have to read the status again to check what actually happened. ! readstatus ! fi ! fi ! ! # Unload any previous tape ! if [ $usedslot -ne "-1" ]; then ! echo " -> unload $usedslot" >> $DBGFILE ! if [ $OFFLINE_BEFORE_UNLOAD -gt 0 ]; then ! $MT $MTF $tape offline ! fi ! result=`$MTX unload $usedslot 2>&1` ! status=$? ! echo " -> status $status, result '$result'" >> $DBGFILE ! if [ $status -ne 0 ]; then ! echo "$loadslot $result" ! exit 2 ! fi ! fi ! ! # Load the tape, finally! ! echo " -> loading tape from slot $loadslot" >> $DBGFILE ! result=`$MTX load $loadslot 2>&1` ! status=$? ! echo " -> status $status, result '$result'" >> $DBGFILE ! ! # If there is an error, abort unless the slot is simply empty ! if [ $status -ne 0 ]; then ! empty=`echo $result | grep "is Empty"` ! if [ -z "$empty" ]; then ! echo "$loadslot $result" ! exit 2 ! else ! loadslot next ! fi else ! # Don't assume the drive is ready until we stop getting tape offline ! readyError="offline" ! while [ -n "$readyError" ]; do ! readyStatus=`$MT $MTF $tape status 2>&1` ! echo " -> readyStatus = $readyStatus" >> $DBGFILE ! readyError=`echo $readyStatus | grep "offline"` ! done ! ! # Now rewind and check ! echo " -> rewind $loadslot" >> $DBGFILE ! $MT $MTF $tape rewind ! echo "$loadslot" > $slotfile ! echo "$loadslot $tape" ! exit 0 fi } ! info() { ! readstatus ! echo "INFO -> current slot $usedslot, last slot $lastslot, can go backwards 1" >> $DBGFILE ! if [ $usedslot -lt 0 ]; then ! echo "0 $lastslot 1" ! else ! echo "$usedslot $lastslot 1" ! fi ! exit 0 } ! ! # Program invocation begins here ! echo "\n`date` Invoked with 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
