8 # fixed last_cleaned file so that if it doesn't exist, it gets created with current date, not '0,0'
9 # fixed a bug that was reporting the wrong slot # to amcheck
13 # amverify was failing when using -slot current. Fixed exit $code from 1 -> 0.
14 # removed useless $current variables from movetape() function.
26 # Set Path so that it includes Amanda binaries, and access to tapechanger & drive programs
29 exec_prefix="@exec_prefix@"
31 amlibexecdir="@amlibexecdir@"
32 . "${amlibexecdir}/amanda-sh-lib.sh"
34 # add sbin and ucb dirs
35 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
40 # Define Suffix for amanda binaries
42 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
43 if test "$USE_VERSION_SUFFIXES" = "yes"; then
50 # Load configuration data from the config file
53 ourconf=`amgetconf$SUF changerfile`
57 if [ ! -f "$ourconf" ]; then
59 echo `_ 'Command Line ->'` $myname $@
60 echo `_ 'Exit(%s): %s not found as listed in amanda.conf' "$code" "$ourconf"` 1>&2
66 tmpval1=`grep ^mcutil $ourconf | awk -F\ '{print $2}'`
67 tmpval2=`grep ^mcutil $ourconf | awk -F= '{print $2}'`
68 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
70 echo `_ 'Command Line ->'` $myname $@
71 echo `_ 'Exit(%s): mcutil not specified in %s' "$code" "$ourconf"` 1>&2
73 elif [ -z "$tmpval1" ]; then
81 tmpval1=`grep ^tape $ourconf | awk -F\ '{print $2}'`
82 tmpval2=`grep ^tape $ourconf | awk -F= '{print $2}'`
83 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
85 echo `_ 'Command Line ->'` $myname $@
86 echo `_ 'Exit(%s): tape not specified in %s' "$code" "$ourconf"` 1>&2
88 elif [ -z "$tmpval1" ]; then
96 tmpval1=`grep ^firstslot $ourconf | awk -F\ '{print $2}'`
97 tmpval2=`grep ^firstslot $ourconf | awk -F= '{print $2}'`
98 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
100 echo `_ 'Command Line ->'` $myname $@
101 echo `_ 'Exit(%s): firstslot not specified in %s' "$code" "$ourconf"` 1>&2
103 elif [ -z "$tmpval1" ]; then
111 tmpval1=`grep ^lastslot $ourconf | awk -F\ '{print $2}'`
112 tmpval2=`grep ^lastslot $ourconf | awk -F= '{print $2}'`
113 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
115 echo `_ 'Command Line ->'` $myname $@
116 echo `_ 'Exit(%s): lastslot not specified in %s' "$code" "$ourconf"` 1>&2
117 elif [ -z "$tmpval1" ]; then
124 # grab use_cleaning info
125 tmpval1=`grep ^use_cleaning $ourconf | awk -F\ '{print $2}'`
126 tmpval2=`grep ^use_cleaning $ourconf | awk -F= '{print $2}'`
127 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
129 echo `_ 'Command Line ->'` $myname $@
130 echo `_ 'Exit(%s): use_cleaning not specified in %s' "$code" "$ourconf"` 1>&2
132 elif [ -z "$tmpval1" ]; then
133 use_cleaning=$tmpval2
135 use_cleaning=$tmpval1
139 # grab cleanslot info
140 tmpval1=`grep ^cleanslot $ourconf | awk -F\ '{print $2}'`
141 tmpval2=`grep ^cleanslot $ourconf | awk -F= '{print $2}'`
142 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
144 echo `_ 'Command Line ->'` $myname $@
145 echo `_ 'Exit(%s): cleanslot not specified in %s' "$code" "$ourconf"` 1>&2
147 elif [ -z "$tmpval1" ]; then
154 # grab cleansleep info
155 tmpval1=`grep ^cleansleep $ourconf | awk -F\ '{print $2}'`
156 tmpval2=`grep ^cleansleep $ourconf | awk -F= '{print $2}'`
157 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
159 echo `_ 'Command Line ->'` $myname $@
160 echo `_ 'Exit(%s): cleansleep not specified in %s' "$code" "$ourconf"` 1>&2
162 elif [ -z "$tmpval1" ]; then
170 tmpval1=`grep ^cleanme $ourconf | awk -F\ '{print $2}'`
171 tmpval2=`grep ^cleanme $ourconf | awk -F= '{print $2}'`
172 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
174 echo `_ 'Command Line ->'` $myname $@
175 echo `_ 'Exit(%s): cleanme not specified in %s' "$code" "$ourconf"` 1>&2
177 elif [ -z "$tmpval1" ]; then
184 # grab cleanfile info
185 tmpval1=`grep ^cleanfile $ourconf | awk -F\ '{print $2}'`
186 tmpval2=`grep ^cleanfile $ourconf | awk -F= '{print $2}'`
187 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
189 echo `_ 'Command Line ->'` $myname $@
190 echo `_ 'Exit(%s): cleanfile not specified in %s' "$code" "$ourconf"` 1>&2
192 elif [ -z "$tmpval1" ]; then
200 tmpval1=`grep ^lastfile $ourconf | awk -F\ '{print $2}'`
201 tmpval2=`grep ^lastfile $ourconf | awk -F= '{print $2}'`
202 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
204 echo `_ 'Command Line ->'` $myname $@
205 echo `_ 'Exit(%s): lastfile not specified in %s' "$code" "$ourconf"` 1>&2
207 elif [ -z "$tmpval1" ]; then
214 # grab currentslot info
215 tmpval1=`grep ^currentslot $ourconf | awk -F\ '{print $2}'`
216 tmpval2=`grep ^currentslot $ourconf | awk -F= '{print $2}'`
217 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
219 echo `_ 'Command Line ->'` $myname $@
220 echo `_ 'Exit(%s): currentslot not specified in %s' "$code" "$ourconf"` 1>&2
222 elif [ -z "$tmpval1" ]; then
230 tmpval1=`grep ^logfile $ourconf | awk -F\ '{print $2}'`
231 tmpval2=`grep ^logfile $ourconf | awk -F= '{print $2}'`
232 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
234 echo `_ 'Command Line ->'` $myname $@
235 echo `_ 'Exit(%s): logfile not specified in %s' "$code" "$ourconf"` 1>&2
237 elif [ -z "$tmpval1" ]; then
243 [ ! -w $logfile ] && logfile=/dev/null
246 # grab slot0source info
247 tmpval1=`grep ^slot0source $ourconf | awk -F\ '{print $2}'`
248 tmpval2=`grep ^slot0source $ourconf | awk -F= '{print $2}'`
249 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
251 echo `_ 'Command Line ->'` $myname $@
252 echo `_ 'Exit(%s): slot0source not specified in %s' "$code" "$ourconf"` 1>&2
254 elif [ -z "$tmpval1" ]; then
263 # Verify currentslot contains a value
265 if [ ! -f $currentslot ] || [ `cat $currentslot` -lt $firstslot ];then
267 echo $used > $currentslot
270 current=`cat $currentslot`
273 # Start logging to $logfile
274 echo "\n\n==== `date` ====" >> $logfile
275 echo `_ 'Command Line ->'` $myname $@ >> $logfile
279 # is Use Cleaning activated?
281 if [ $use_cleaning -eq 1 ]; then
285 [ ! -f $cleanfile ] && echo 0 > $cleanfile
286 [ ! -f $lastfile ] && echo $curday,$curyear > $lastfile
290 # Check to see when tape drive was last cleaned
291 # output warning message if it's been too long
292 # Currently, if it's been more than 45days, then
293 # an error message is displayed everytime the
294 # script is called, until the clean parameter
297 cleaned=`cat $cleanfile`
298 lastcleaned=`cut -d, -f1 $lastfile`
299 yearcleaned=`cut -d, -f2 $lastfile`
301 if [ `expr $curday - $lastcleaned` -lt 0 ];then
302 diffday=`expr $curday - $lastcleaned + 365`
303 diffyear=`expr $curyear - $yearcleaned - 1`
305 diffday=`expr $curday - $lastcleaned`
306 diffyear=`expr $curyear - $yearcleaned`
309 if [ $diffday -gt $cleanme ] || [ $diffyear -ge 1 ];then
310 if [ $diffyear -ge 1 ];then
311 echo `_ "Warning, it's been %s year(s) & %s day(s) since you last cleaned the tape drive!" "$diffyear" "$diffday"`
313 echo `_ "Warning, it's been %s day(s) since you last cleaned the tape drive!" "$diffday"`
321 # Read if there is a tape in the tape drive
322 # If so, determine what slot is the tape from
325 echo `_ "querying tape drive....."` >> $logfile
326 used=`expr \`$MCUTIL -e drive | tr = \] | cut -d\] -f2\` - $slot0source`
327 echo `_ " Done"` >> $logfile
329 # Give changer a chance to reset itself
335 # If tape is in the drive, eject it
338 echo `_ "tape drive eject was called"` >> $logfile
342 if [ $used -ge $firstslot ];then
343 $MCUTIL -m drive slot:$used
349 if [ $code -eq 0 ];then
350 answer=`_ 'Cartridge %s successfully ejected from %s' "$used" "$tape"`
351 echo `_ "Exit(%s): %s" "$code" "$answer"` >> $logfile
352 echo $current $answer #For amtape output
354 elif [ $code -eq 1 ];then
355 answer=`_ "No Cartridge in Tape Drive"`
356 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
357 echo $current $answer #For amtape output
360 answer=`_ 'Tape abnormally failed'`
361 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
362 echo $current $answer #For amtape output
369 # reset tape drive to a current state.
370 # This involves ejecting the current tape (if occupied)
371 # and inserting the tape in $firstslot
374 echo `_ 'tape drive reset was called'` >> $logfile
378 if [ $used -ge $firstslot ];then
382 res=`$MCUTIL -m slot:$firstslot drive`
386 if [ $code -eq 0 ];then
387 echo $firstslot > $currentslot
388 answer=`_ '%s - Tape drive was successfully reset' "$firstslot"`
389 elif [ $code -eq 1 ];then
390 answer=`_ '%s - Tape drive reset failed\nCommand -> %s' "$firstslot" "$res"`
393 answer=`_ '%s - Tape abnormally failed -> %s' "$firstslot" "$res"`
396 echo `_ 'Exit(%s): slot %s' "$code" "$answer"` >> $logfile
397 echo $firstslot #For amtape output
405 # Load a specific cartridge into the changer
408 echo `_ "loadslot was called"` >> $logfile
416 if [ $current -ge $firstslot ];then
425 [ $used -lt $firstslot ] && used=$current
427 load=`expr $used + 1`
428 [ $load -gt $lastslot ] && load=$firstslot
430 if [ $whichslot = advance ];then
431 echo $load > $currentslot
433 answer=`_ 'advancing to slot %s' "$load"`
434 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
442 [ $used -lt $firstslot ] && used=$current
444 load=`expr $used - 1`
445 [ $load -lt $firstslot ] && load=$lastslot
456 [$firstslot-$lastslot])
461 if [ use_cleaning -eq 1 ];then
464 $MCUTIL slot:$cleanslot drive
466 echo "$curday,$curyear" > $lastfile
467 echo `expr $cleaned + 1` > $cleanfile
471 answer=`_ "Cleaning not enabled in config"`
472 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
473 echo $cleanslot $answer
479 answer=`_ '"%s" invalid menu option' "$whichslot"`
480 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
489 # sub-function that slot calls to actually eject the tape
490 # & load in the correct slot cartridge
494 # If the requested slot is already loaded in the tape drive
495 if [ $load -eq $used ]; then
497 answer=`_ 'slot %s is already loaded' "$load"`
498 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
499 echo $load $tape # For amtape output
501 elif [ $used -ge $firstslot ];then
505 echo $load $tape # For amtape output
508 echo `_ 'Loading slot %s into Tape drive' "$load"` >> $logfile
509 $MCUTIL -m slot:$load drive
512 if [ $code -eq 0 ];then
513 echo $load > $currentslot
514 answer=`_ 'Cartridge %s successfully loaded in Tape drive' "$load"`
516 answer=`_ 'Cartridge %s failed to load in Tape drive' "$load"`
518 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
524 echo `_ 'tape drive info was called'` >> $logfile
528 if [ $used -lt 0 ];then
533 answer="$used $lastslot 1"
534 echo `_ 'Exit(%s): %s' "$code" "$answer"` >> $logfile
561 echo `_ '-slot {current|next|previous|first|last|%s-%s|clean}' "$firstslot" "$lastslot"`
562 echo `_ ' current - show contents of current slot'`
563 echo `_ ' next - load tape from next slot'`
564 echo `_ ' previous - load tape from previous slot'`
565 echo `_ ' first - load tape from first slot'`
566 echo `_ ' last - load tape from last slot'`
567 echo `_ ' %s - %s - load tape from slot <slot #>' "$firstslot" "$lastslot"`
568 echo `_ ' clean - Clean the drive'`
569 echo `_ '-device : Show current tape device'`
570 echo `_ '-reset : Reset changer to known state'`
571 echo `_ '-eject : Eject current tape from drive'`
572 echo `_ '-info : Output {current slot | # of slots | can changer go backwards}'`
573 echo `_ '-help : Display this help'`
576 echo `_ "<usage> %s -{slot|device|reset|eject|help}" "$myname"`