📄 chg-zd-mtx.sh
字号:
s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^ ]*\)/\1 \2/p q}/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^ ]*\)/ { s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^ ]*\)/\1 \2/p q}/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded):VolumeTag *= *\([^ ]*\)/ { s/.*:VolumeTag *= *\([^ ]*\)/-2 \1/p q}/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded)/ { s/.*(Storage Element \([0-9][0-9]*\) Loaded).*/\1/p q}/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded)/ { s/.*Storage Element \([0-9][0-9]*\) Loaded.*/\1/p q}/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded)/ { s/.*/-2/p q}' < $mtx_status 2>&1` shift # get rid of the "x" loadedslot=$1 loadedbarcode=$2 if [ -z "$loadedslot" ]; then Exit 2 \ `_ '<none>'` \ "could not determine current slot, are you sure your drive slot is $driveslot" return $? # in case we are internal fi #Use the current slot if it's empty and we don't know which slot is loaded' if [ $loadedslot -eq -2 ]; then set x `sed -n '{ /^.*Storage Element '$currentslot':Empty/ { s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p q } /^.*Storage Element '$currentslot':Full/ { s/.*Storage Element \([0-9][0-9]*\):Full/-2/p q } /^.*Storage Element '$currentslot' IMPORT\/EXPORT:Empty/ { s/.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Empty/\1/p q } /^.*Storage Element '$currentslot' IMPORT\/EXPORT:Full/ { s/.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Full/-2/p q }}' < $mtx_status 2>& 1` shift # get rid of the "x" loadedslotx=$1 if [ ! -z $loadedslotx ]; then loadedslot=$loadedslotx fi fi #Use the first empty slot if we don't know which slot is loaded' if [ $loadedslot -eq -2 ]; then set x `sed -n '{ /^.*Storage Element \([0-9][0-9]*\):Empty/ { s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p q } /^.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Empty/ { s/.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Empty/\1/p q }}' < $mtx_status 2>& 1` shift # get rid of the "x" loadedslot=$1 fi if IsNumeric "$loadedslot" ; then : else Exit 2 \ `_ '<none>'` \ "currently loaded slot ($loadedslot) not numeric" return $? # in case we are internal fi Log `_ 'STATUS -> currently loaded slot = %s' "$loadedslot"` LogAppend `_ ' -> currently loaded barcode = "%s"' "$loadedbarcode"`}#### Get a list of slots between $firstslot and $lastslot, if they are set.# If they are not set, set them to the first and last slot seen on the# assumption the entire robot is to be used (???).###slot_list=get_slot_list() { test -n "$DEBUG" && set -x if [ -n "$slot_list" ]; then return fi get_mtx_status slot_list=`sed -n '/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded)/ { s/.*(Storage Element \([0-9][0-9]*\) Loaded).*/\1/p}/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded)/ { s/.*Storage Element \([0-9][0-9]*\) Loaded.*/\1/p}/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded)/ { : loop n /^.*Storage Element \([0-9][0-9]*\):Full/ { s/.*Storage Element \([0-9][0-9]*\):Full.*/\1/p b loop } /^.*Storage Element \([0-9][0-9]*\):Empty/ { s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p }}/^.*Storage Element \([0-9][0-9]*\):Full/ { s/.*Storage Element \([0-9][0-9]*\):Full.*/\1/p}/^.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Full/ { s/.*Storage Element \([0-9][0-9]*\) IMPORT\/EXPORT:Full.*/\1/p}' < $mtx_status 2>&1 | grep -v "^${cleanslot}\$" | sort -n` slot_list=`echo $slot_list` # remove the newlines if [ $firstslot -lt 0 -o $lastslot -lt 0 ]; then last=$lastslot for slot in $slot_list; do if [ $firstslot -lt 0 ]; then Log `_ 'SLOTLIST -> firstslot set to %s' "$slot"` firstslot=$slot fi if [ $lastslot -lt 0 ]; then last=$slot fi done if [ $lastslot -lt 0 -a $last -ge 0 ]; then Log `_ 'SLOTLIST -> lastslot set to %s' "$last"` lastslot=$last fi if [ $firstslot -lt 0 ]; then Exit 2 \ `_ '<none>'` \ `_ 'cannot determine first slot'` return $? # in case we are internal elif [ $lastslot -lt 0 ]; then Exit 2 \ `_ '<none>'` \ `_ 'cannot determine last slot'` return $? # in case we are internal fi fi amanda_slot_list= for slot in $slot_list; do if [ $slot -ge $firstslot -a $slot -le $lastslot ]; then amanda_slot_list="$amanda_slot_list $slot" fi done if [ -z "$amanda_slot_list" ]; then Exit 2 \ `_ '<none>'` \ "no slots available" return $? # in case we are internal fi slot_list="$amanda_slot_list"}DBGFILE=`amgetconf dbopen.$argv0 2>/dev/null`if [ -z "$DBGFILE" ]then DBGFILE=/dev/null # will try this again belowfichangerfile=`amgetconf changerfile 2>/dev/null`if [ -z "$changerfile" ]; then Exit 2 \ `_ '<none>'` \ "changerfile must be specified in amanda.conf"firawtape=`amgetconf tapedev 2>/dev/null`if [ -z "$rawtape" ]; then Exit 2 \ `_ '<none>'` \ "tapedev may not be empty"fitape=`tape_device_filename "$rawtape"`if [ -z "$tape" ]; then Exit 2 \ ` _ '<none>'` \ "tapedev $rawtape is not a tape device."elif [ $tape = "/dev/null" -o `expr "$tape" : 'null:'` -eq 5 ]; then Exit 2 \ `_ '<none>'` \ "tapedev ($tape) may not be the null device"fi# Confusingly, TAPE is the name of the changer device...TAPE=`amgetconf changerdev 2>/dev/null`if [ -z "$TAPE" ]; then Exit 2 \ `_ '<none>'` \ "changerdev may not be empty"elif [ $TAPE = "/dev/null" ]; then Exit 2 \ `_ '<none>'` \ "changerdev ($TAPE) may not be the null device"fiexport TAPE # for mtx commandCHANGER=$TAPE export CHANGER # for mtx command#### Set up the various config files.conf_match=`expr "$changerfile" : .\*\.conf\$`if [ $conf_match -ge 6 ]; then configfile=$changerfile changerfile=`echo $changerfile | sed 's/.conf$//g'`else configfile=$changerfile.conffiif [ ! -e $configfile ]; then Exit 2 \ `_ '<none>'` \ "configuration file \"$configfile\" doesn't exist"fiif [ ! -f $configfile ]; then Exit 2 \ `_ '<none>'` \ "configuration file \"$configfile\" is not a file"ficleanfile=$changerfile-cleanaccessfile=$changerfile-accessslotfile=$changerfile-slotlabelfile=$changerfile-barcodes[ ! -s $cleanfile ] && echo 0 > $cleanfile[ ! -s $accessfile ] && echo 0 > $accessfile[ ! -s $slotfile ] && echo -1 > $slotfile[ ! -f $labelfile ] && > $labelfilecleancount=`cat $cleanfile`accesscount=`cat $accessfile`#### Dig out of the config file what is neededvarlist=varlist="$varlist firstslot"varlist="$varlist lastslot"varlist="$varlist cleanslot"varlist="$varlist cleancycle"varlist="$varlist OFFLINE_BEFORE_UNLOAD" # old namevarlist="$varlist offline_before_unload"varlist="$varlist unloadpause"varlist="$varlist AUTOCLEAN" # old namevarlist="$varlist autoclean"varlist="$varlist autocleancount"varlist="$varlist havereader"varlist="$varlist driveslot"varlist="$varlist poll_drive_ready"varlist="$varlist initial_poll_delay"varlist="$varlist max_drive_wait"for var in $varlistdo val="`cat $configfile 2>/dev/null | sed -n '# Ignore comment lines (anything starting with a #)./^[ ]*#/d# Find the first var=val line in the file, print the value and quit./^[ ]*'$var'[ ]*=[ ]*\([^ ][^ ]*\).*/ { s/^[ ]*'$var'[ ]*=[ ]*\([^ ][^ ]*\).*/\1/p q}'`" eval $var=\"$val\"done# Deal with driveslot first so we can get DBGFILE set if we are still# using the old amgetconf.if [ -z "$driveslot" ]; then driveslot=0;fi# Get DBGFILE set if it is not already.if [ $DBGFILE = /dev/null ]; then if [ -d "$DBGDIR" ]; then DBGFILE=$DBGDIR/changer.debug.drive$driveslot else DBGFILE=/dev/null fi Log `_ '=== Start %s ===' "\`date\`"`fistdout=$TMPDIR/$myname.1.$$stderr=$TMPDIR/$myname.2.$$mtx_status=$TMPDIR/$myname.status.$$trap "rm -f $stdout $stderr $mtx_status" 0 # exit cleanupLog `_ 'Using config file %s' "$configfile"`# Log the argument list.Log `_ "Arg info:"`LogAppend "\$# = $#"i=0LogAppend "\$$i = \"$argv0\""for arg in "$@"; do i=`expr $i + 1` LogAppend "\$$i = \"$arg\""done# Set the default config values for those not in the file. Log the# results and make sure each is valid (numeric).firstslot=${firstslot:-'-1'} # default: mtx statuslastslot=${lastslot:-'-1'} # default: mtx statuscleanslot=${cleanslot:-'-1'} # default: -1cleancycle=${cleancycle:-'120'} # default: two minutesif [ -z "$offline_before_unload" -a -n "$OFFLINE_BEFORE_UNLOAD" ]; then offline_before_unload=$OFFLINE_BEFORE_UNLOAD # (old name)fioffline_before_unload=${offline_before_unload:-'0'} # default: 0unloadpause=${unloadpause:-'0'} # default: 0if [ -z "$autoclean" -a -n "$AUTOCLEAN" ]; then autoclean=$AUTOCLEAN # (old name)fiautoclean=${autoclean:-'0'} # default: 0autocleancount=${autocleancount:-'99'} # default: 99havereader=${havereader:-'0'} # default: 0poll_drive_ready=${poll_drive_ready:-'3'} # default: three secondsinitial_poll_delay=${initial_poll_delay:-'0'} # default: zero zecondsmax_drive_wait=${max_drive_wait:-'120'} # default: two minutes# check MT and MTX for sanityif test "${MTX:0:1}" = "/"; then if ! test -f "${MTX}"; then Exit 2 \ `_ '<none>'` \ `_ "mtx binary at '%s' not found" "$MTX"` fi if ! test -x "${MTX}"; then Exit 2 \ `_ '<none>'` \ `_ "mtx binary at '%s' is not executable" "$MTX"` fielse # try running it to see if the shell can find it "$MTX" >/dev/null 2>/dev/null if test $? -eq 127 -o $? -eq 126; then Exit 2 \ `_ '<none>'` \ `_ "Could not run mtx binary at '%s'" "$MTX"` fifierror=`try_find_mt`if test $? -ne 0; then Exit 2 '<none>' $errorfiget_slot_listLog `_ "Config info:"`for var in $varlist; do if [ $var = "OFFLINE_BEFORE_UNLOAD" ]; then continue # old name elif [ $var = "AUTOCLEAN" ]; then continue # old name fi eval val=\"'$'$var\" if [ -z "$val" ]; then Exit 2 \ `_ '<none>'` \ `_ '%s missing in %s' "$var" "$configfile"` fi if IsNumeric "$val" ; then : else Exit 2 \ `_ '<none>'` \ `_ '%s (%s) not numeric in %s' "$var" "$val" "$configfile"` fi LogAppend $var = \"$val\"done# Run the rest of the config file sanity checks.if [ $firstslot -gt $lastslot ]; then Exit 2 \ `_ '<none>'` \ `_ 'firstslot (%s) greater than lastslot (%s) in %s' "$firstslot" "$lastslot" "$configfile"`fiif [ $autoclean -ne 0 -a $cleanslot -lt 0 ]; then Exit 2 \ `_ '<none>'` \ `_ 'autoclean set but cleanslot not valid (%s)' "$cleanslot"`fi# Set up the current slotcurrentslot=`cat $slotfile`if IsNumeric "$currentslot" ; then if [ $currentslot -lt $firstslot ]; then Log `_ 'SETUP -> current slot %s less than %s ... resetting to %s' "$currentslot" "$firstslot" "$firstslot"` currentslot=$firstslot elif [ $currentslot -gt $lastslot ]; then Log `_ 'SETUP -> current slot %s greater than %s ... resetting to %s' "$currentslot" "$lastslot" "$lastslot"` currentslot=$lastslot fielse Log `_ 'SETUP -> contents of %s (%s) invalid, setting current slot to first slot (%s)' "$slotfile" "$currentslot" "$firstslot"` currentslot=$firstslotfifound_current=0first_slot_in_list=-1next_slot_after_current=-1for slot in $slot_list; do if [ $first_slot_in_list -lt 0 ]; then first_slot_in_list=$slot # in case $firstslot is missing fi if [ $slot -eq $currentslot ]; then found_current=1 break elif [ $slot -gt $currentslot ]; then next_slot_after_current=$slot # $currentslot is missing break fidoneif [ $found_current -eq 0 ]; then if [ $next_slot_after_current -lt 0 ]; then new_currentslot=$first_slot_in_list else new_currentslot=$next_slot_after_current fi Log `_ 'WARNING -> current slot %s not available, setting current slot to next slot (%s)' "$currentslot" "$new_currentslot"` currentslot=$new_currentslotfi# More routines.#### Eject the current tape and put it away.###eject() { test -n "$DEBUG" && set -x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -