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 libexecdir=@libexecdir@
33 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin
38 # Define Suffix for amanda binaries
40 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
41 if test "$USE_VERSION_SUFFIXES" = "yes"; then
49 # Load configuration data from the config file
52 ourconf=`amgetconf$SUF changerfile`
56 if [ ! -f "$ourconf" ]; then
58 echo "Command Line -> $myname $@\nExit($code): $ourconf not found as listed in amanda.conf"
64 tmpval1=`grep ^mcutil $ourconf | awk -F\ '{print $2}'`
65 tmpval2=`grep ^mcutil $ourconf | awk -F= '{print $2}'`
66 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
68 echo "Command Line -> $myname $@ \nExit($code): mcutil not specified in $ourconf"
70 elif [ -z "$tmpval1" ]; then
78 tmpval1=`grep ^tape $ourconf | awk -F\ '{print $2}'`
79 tmpval2=`grep ^tape $ourconf | awk -F= '{print $2}'`
80 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
82 echo "Command Line -> $myname $@ \nExit($code): tape not specified in $ourconf"
84 elif [ -z "$tmpval1" ]; then
92 tmpval1=`grep ^firstslot $ourconf | awk -F\ '{print $2}'`
93 tmpval2=`grep ^firstslot $ourconf | awk -F= '{print $2}'`
94 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
96 echo "Command Line -> $myname $@ \nExit($code): firstslot not specified in $ourconf"
98 elif [ -z "$tmpval1" ]; then
106 tmpval1=`grep ^lastslot $ourconf | awk -F\ '{print $2}'`
107 tmpval2=`grep ^lastslot $ourconf | awk -F= '{print $2}'`
108 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
110 echo "Command Line -> $myname $@ \nExit($code): lastslot not specified in $ourconf"
112 elif [ -z "$tmpval1" ]; then
119 # grab use_cleaning info
120 tmpval1=`grep ^use_cleaning $ourconf | awk -F\ '{print $2}'`
121 tmpval2=`grep ^use_cleaning $ourconf | awk -F= '{print $2}'`
122 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
124 echo "Command Line -> $myname $@ \nExit($code): use_cleaning not specified in $ourconf"
126 elif [ -z "$tmpval1" ]; then
127 use_cleaning=$tmpval2
129 use_cleaning=$tmpval1
133 # grab cleanslot info
134 tmpval1=`grep ^cleanslot $ourconf | awk -F\ '{print $2}'`
135 tmpval2=`grep ^cleanslot $ourconf | awk -F= '{print $2}'`
136 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
138 echo "Command Line -> $myname $@ \nExit($code): cleanslot not specified in $ourconf"
140 elif [ -z "$tmpval1" ]; then
147 # grab cleansleep info
148 tmpval1=`grep ^cleansleep $ourconf | awk -F\ '{print $2}'`
149 tmpval2=`grep ^cleansleep $ourconf | awk -F= '{print $2}'`
150 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
152 echo "Command Line -> $myname $@ \nExit($code): cleansleep not specified in $ourconf"
154 elif [ -z "$tmpval1" ]; then
162 tmpval1=`grep ^cleanme $ourconf | awk -F\ '{print $2}'`
163 tmpval2=`grep ^cleanme $ourconf | awk -F= '{print $2}'`
164 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
166 echo "Command Line -> $myname $@ \nExit($code): cleanme not specified in $ourconf"
168 elif [ -z "$tmpval1" ]; then
175 # grab cleanfile info
176 tmpval1=`grep ^cleanfile $ourconf | awk -F\ '{print $2}'`
177 tmpval2=`grep ^cleanfile $ourconf | awk -F= '{print $2}'`
178 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
180 echo "Command Line -> $myname $@ \nExit($code): cleanfile not specified in $ourconf"
182 elif [ -z "$tmpval1" ]; then
190 tmpval1=`grep ^lastfile $ourconf | awk -F\ '{print $2}'`
191 tmpval2=`grep ^lastfile $ourconf | awk -F= '{print $2}'`
192 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
194 echo "Command Line -> $myname $@ \nExit($code): lastfile not specified in $ourconf"
196 elif [ -z "$tmpval1" ]; then
203 # grab currentslot info
204 tmpval1=`grep ^currentslot $ourconf | awk -F\ '{print $2}'`
205 tmpval2=`grep ^currentslot $ourconf | awk -F= '{print $2}'`
206 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
208 echo "Command Line -> $myname $@ \nExit($code): currentslot not specified in $ourconf"
210 elif [ -z "$tmpval1" ]; then
218 tmpval1=`grep ^logfile $ourconf | awk -F\ '{print $2}'`
219 tmpval2=`grep ^logfile $ourconf | awk -F= '{print $2}'`
220 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
222 echo "Command Line -> $myname $@ \nExit($code): logfile not specified in $ourconf"
224 elif [ -z "$tmpval1" ]; then
230 [ ! -w $logfile ] && logfile=/dev/null
233 # grab slot0source info
234 tmpval1=`grep ^slot0source $ourconf | awk -F\ '{print $2}'`
235 tmpval2=`grep ^slot0source $ourconf | awk -F= '{print $2}'`
236 if [ -z "$tmpval1" ] && [ -z "$tmpval2" ]; then
238 echo "Command Line -> $myname $@ \nExit($code): slot0source not specified in $ourconf"
240 elif [ -z "$tmpval1" ]; then
249 # Verify currentslot contains a value
251 if [ ! -f $currentslot ] || [ `cat $currentslot` -lt $firstslot ];then
253 echo $used > $currentslot
256 current=`cat $currentslot`
259 # Start logging to $logfile
260 echo "\n\n==== `date` ====" >> $logfile
261 echo "Command Line -> $myname $@" >> $logfile
265 # is Use Cleaning activated?
267 if [ $use_cleaning -eq 1 ]; then
271 [ ! -f $cleanfile ] && echo 0 > $cleanfile
272 [ ! -f $lastfile ] && echo $curday,$curyear > $lastfile
276 # Check to see when tape drive was last cleaned
277 # output warning message if it's been too long
278 # Currently, if it's been more than 45days, then
279 # an error message is displayed everytime the
280 # script is called, until the clean parameter
283 cleaned=`cat $cleanfile`
284 lastcleaned=`cut -d, -f1 $lastfile`
285 yearcleaned=`cut -d, -f2 $lastfile`
287 if [ `expr $curday - $lastcleaned` -lt 0 ];then
288 diffday=`expr $curday - $lastcleaned + 365`
289 diffyear=`expr $curyear - $yearcleaned - 1`
291 diffday=`expr $curday - $lastcleaned`
292 diffyear=`expr $curyear - $yearcleaned`
295 if [ $diffday -gt $cleanme ] || [ $diffyear -ge 1 ];then
296 if [ $diffyear -ge 1 ];then
297 echo "Warning, it's been $diffyear year(s) & $diffday days since you last cleaned the tape drive!"
299 echo "Warning, it's been $diffday days since you last cleaned the tape drive!"
307 # Read if there is a tape in the tape drive
308 # If so, determine what slot is the tape from
311 echo -n "querying tape drive....." >> $logfile
312 used=`expr \`$MCUTIL -e drive | tr = \] | cut -d\] -f2\` - $slot0source`
313 echo " Done" >> $logfile
315 # Give changer a chance to reset itself
321 # If tape is in the drive, eject it
324 echo "tape drive eject was called" >> $logfile
328 if [ $used -ge $firstslot ];then
329 $MCUTIL -m drive slot:$used
335 if [ $code -eq 0 ];then
336 answer="Cartridge $used successfully ejected from $tape"
337 echo "Exit($code): $answer" >> $logfile
338 echo $current $tape #For amtape output
340 elif [ $code -eq 1 ];then
341 answer="No Cartridge in Tape Drive"
342 echo "Exit($code): $answer" >> $logfile
343 echo $current $answer #For amtape output
346 answer="Tape abnormally failed"
347 echo "Exit($code): $answer" >> $logfile
348 echo $current $answer #For amtape output
355 # reset tape drive to a current state.
356 # This involves ejecting the current tape (if occupied)
357 # and inserting the tape in $firstslot
360 echo "tape drive reset was called" >> $logfile
364 if [ $used -ge $firstslot ];then
368 res=`$MCUTIL -m slot:$firstslot drive`
372 if [ $code -eq 0 ];then
373 echo $firstslot > $currentslot
374 answer="$firstslot - Tape drive was successfully reset"
375 elif [ $code -eq 1 ];then
376 answer="$firstslot - Tape drive reset failed\nCommand -> $res"
379 answer="$firstlot - Tape abnormally failed -> $res"
382 echo "Exit($code): slot $answer" >> $logfile
383 echo $firstslot #For amtape output
391 # Load a specific cartridge into the changer
394 echo "loadslot was called" >> $logfile
402 if [ $current -ge $firstslot ];then
411 [ $used -lt $firstslot ] && used=$current
413 load=`expr $used + 1`
414 [ $load -gt $lastslot ] && load=$firstslot
416 if [ $whichslot = advance ];then
417 echo $load > $currentslot
419 answer="advancing to slot $load"
420 echo "Exit($code): $answer" >> $logfile
428 [ $used -lt $firstslot ] && used=$current
430 load=`expr $used - 1`
431 [ $load -lt $firstslot ] && load=$lastslot
442 [$firstslot-$lastslot])
447 if [ use_cleaning -eq 1 ];then
450 $MCUTIL slot:$cleanslot drive
452 echo "$curday,$curyear" > $lastfile
453 echo `expr $cleaned + 1` > $cleanfile
457 answer="Cleaning not enabled in config" >> $logfile
458 echo "Exit($code): $answer" >> $logfile
459 echo $cleanslot $answer
465 answer="\"$whichslot\" invalid menu option"
466 echo "Exit($code): slot $answer" >> $logfile
475 # sub-function that slot calls to actually eject the tape
476 # & load in the correct slot cartridge
480 # If the requested slot is already loaded in the tape drive
481 if [ $load -eq $used ]; then
483 answer="$load is already loaded"
484 echo "Exit($code): slot $answer" >> $logfile
485 echo $load $tape # For amtape output
487 elif [ $used -ge $firstslot ];then
491 echo $load $tape # For amtape output
494 echo "Loading slot $load into Tape drive" >> $logfile
495 $MCUTIL -m slot:$load drive
498 if [ $code -eq 0 ];then
499 echo $load > $currentslot
500 answer="Cartridge $load successfully loaded in Tape drive"
502 answer="Cartridge $load failed to load in Tape drive"
504 echo "Exit($code): $answer" >> $logfile
510 echo "tape drive info was called" >> $logfile
514 if [ $used -lt 0 ];then
519 answer="$used $lastslot 1"
520 echo "Exit($code): $answer" >> $logfile
547 echo "-slot {current|next|previous|first|last|$firstslot-$lastslot|clean}"
548 echo " current - show contents of current slot"
549 echo " next - load tape from next slot"
550 echo " previous - load tape from previous slot"
551 echo " first - load tape from first slot"
552 echo " last - load tape from last slot"
553 echo " $firstslot - $lastslot - load tape from slot <slot #>"
554 echo " clean - Clean the drive"
555 echo "-device : Show current tape device"
556 echo "-reset : Reset changer to known state"
557 echo "-eject : Eject current tape from drive"
558 echo "-info : Output {current slot | # of slots | can changer go backwards}"
559 echo "-help : Display this help"
562 echo "<usage> $myname -{slot|device|reset|eject|help}"