9 # try to hit all the possibilities here
11 exec_prefix=@exec_prefix@
13 libexecdir=@libexecdir@
15 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin
18 if [ -d "@AMANDA_DBGDIR@" ]; then
19 logfile=@AMANDA_DBGDIR@/changer.debug
24 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
25 if test "$USE_VERSION_SUFFIXES" = "yes"; then
33 tape=`amgetconf$SUF tapedev`
34 if [ -z "$tape" ]; then
35 echo "<none> tapedev not specified in amanda.conf";
39 TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command
40 if [ -z "$TAPE" ]; then
41 echo "<none> changerdev not specified in amanda.conf";
45 if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then
46 echo "<none> Both tapedev and changerdev must be specified in config file";
52 if [ -x $sbindir/ammt$SUF ]; then
55 elif [ -x "@MT@" ]; then
59 answer="<none> $myname: mt program not found"
61 echo "Exit -> $answer" >> $logfile
65 echo MT "->" $MT $MTF >> $logfile
67 if [ -x $sbindir/amdd$SUF ]; then
69 elif [ -x "@DD@" ]; then
72 answer="<none> $myname: dd program not found"
74 echo "Exit -> $answer" >> $logfile
78 echo DD "->" $DD >> $logfile
85 changerfile=`amgetconf$SUF changerfile`
87 cleanfile=$changerfile-clean
88 accessfile=$changerfile-access
89 [ ! -f $cleanfile ] && echo 0 > $cleanfile
90 [ ! -f $accessfile ] && echo 0 > $accessfile
91 cleancount=`cat $cleanfile`
92 accesscount=`cat $accessfile`
97 sed -n 's/Drive: No tape Loaded/-1/p;s/Drive: tape \(.\) loaded/\1/p'`
99 if [ -z "$used" ]; then
107 if [ $used -gt 0 ];then
111 echo "Exit -> $answer" >> $logfile
115 answer="<none> $myname: Drive was not loaded"
117 echo "Exit -> $answer" >> $logfile
125 if [ $used -gt 0 ];then
132 echo "Exit -> $answer" >> $logfile
138 echo "Exit -> $answer" >> $logfile
147 echo " -> loaded $used" >> $logfile
151 if [ $used -lt 0 ];then
157 echo "Exit -> $answer" >> $logfile
162 load=`expr $used + 1`
163 [ $load -gt $lastslot ] && load=$firstslot
166 load=`expr $used - 1`
167 [ $load -lt $firstslot ] && load=$lastslot
175 [$firstslot-$lastslot])
182 answer="<none> $myname: illegal request: \"$whichslot\""
184 echo "Exit -> $answer" >> $logfile
190 if [ $load = $used ]; then
193 echo "Exit -> $answer" >> $logfile
198 if [ $load = $cleanslot ]; then
199 expr $cleancount + 1 > $cleanfile
202 expr $accesscount + 1 > $accessfile
203 if [ $accesscount -gt 9 ]; then
204 $myname -slot clean >/dev/null
208 # Slot 6 might contain an ordinary tape rather than a cleaning
209 # tape. A cleaning tape auto-ejects; an ordinary tape does not.
210 # We therefore have to read the status again to check what
215 if [ $used -gt 0 ];then
216 echo " -> unload $used" >> $logfile
219 echo " -> status $status" >> $logfile
220 echo " -> res $res" >> $logfile
221 if [ $status -ne 0 ];then
222 answer="<none> $myname: $res"
224 echo "Exit -> $answer" >> $logfile
229 if [ $whichslot = advance ];then
230 answer="$load /dev/null"
232 echo "Exit -> $answer" >> $logfile
236 echo " -> load $load" >> $logfile
239 echo " -> status $status" >> $logfile
240 echo " -> res $res" >> $logfile
241 if [ $status -eq 0 ];then
242 echo " -> rew $load" >> $logfile
243 $MT $MTF $tape rewind
244 $DD if=$tape bs=32k count=1 >> $logfile 2>&1
251 echo "Exit -> $answer" >> $logfile
258 echo " -> info $used" >> $logfile
259 if [ $used -lt 0 ];then
262 answer="$used $lastslot 1"
264 echo "Exit -> $answer" >> $logfile
269 echo Args "->" "$@" >> $logfile
270 while [ $# -ge 1 ];do
289 answer="<none> $myname: Unknown option $1"
291 echo "Exit -> $answer" >> $logfile