9 # source utility functions and values from configure
11 exec_prefix=@exec_prefix@
12 amlibexecdir=@amlibexecdir@
13 . ${amlibexecdir}/chg-lib.sh
15 if [ -d "@AMANDA_DBGDIR@" ]; then
16 logfile=@AMANDA_DBGDIR@/changer.debug
23 tape=`amgetconf tapedev`
24 if [ -z "$tape" ]; then
25 echo "<none> tapedev not specified in amanda.conf";
29 TAPE=`amgetconf changerdev`; export TAPE # for mtx command
30 if [ -z "$TAPE" ]; then
31 echo "<none> changerdev not specified in amanda.conf";
35 if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then
36 echo "<none> Both tapedev and changerdev must be specified in config file";
45 changerfile=`amgetconf changerfile`
47 cleanfile=$changerfile-clean
48 accessfile=$changerfile-access
49 [ ! -f $cleanfile ] && echo 0 > $cleanfile
50 [ ! -f $accessfile ] && echo 0 > $accessfile
51 cleancount=`cat $cleanfile`
52 accesscount=`cat $accessfile`
57 sed -n 's/Drive: No tape Loaded/-1/p;s/Drive: tape \(.\) loaded/\1/p'`
59 if [ -z "$used" ]; then
67 if [ $used -gt 0 ];then
70 echo `_ 'Exit ->'` $answer >> $logfile
74 answer=`_ '<none> %s: Drive was not loaded' "$myname"`
75 echo `_ 'Exit ->'` $answer >> $logfile
83 if [ $used -gt 0 ];then
89 echo `_ 'Exit ->'` $answer >> $logfile
94 echo `_ 'Exit ->'` $answer >> $logfile
103 echo " -> loaded $used" >> $logfile
107 if [ $used -lt 0 ];then
112 echo `_ 'Exit ->'` $answer >> $logfile
117 load=`expr $used + 1`
118 [ $load -gt $lastslot ] && load=$firstslot
121 load=`expr $used - 1`
122 [ $load -lt $firstslot ] && load=$lastslot
130 [$firstslot-$lastslot])
137 answer=`_ '<none> %s: illegal request: "%s"' "$myname" "$whichslot"`
138 echo `_ 'Exit ->'` $answer >> $logfile
144 if [ $load = $used ]; then
146 echo `_ 'Exit ->'` $answer >> $logfile
151 if [ $load = $cleanslot ]; then
152 expr $cleancount + 1 > $cleanfile
155 expr $accesscount + 1 > $accessfile
156 if [ $accesscount -gt 9 ]; then
157 $myname -slot clean >/dev/null
161 # Slot 6 might contain an ordinary tape rather than a cleaning
162 # tape. A cleaning tape auto-ejects; an ordinary tape does not.
163 # We therefore have to read the status again to check what
168 if [ $used -gt 0 ];then
169 echo " -> unload $used" >> $logfile
172 echo " -> status $status" >> $logfile
173 echo " -> res $res" >> $logfile
174 if [ $status -ne 0 ];then
175 answer=`_ '<none> %s: %s' "$myname" "$res"`
176 echo `_ 'Exit ->'` $answer >> $logfile
181 if [ $whichslot = advance ];then
182 answer="$load /dev/null"
183 echo `_ 'Exit ->'` $answer >> $logfile
187 echo `_ ' -> load %s' "$load"` >> $logfile
190 echo `_ ' -> status %s' "$status"` >> $logfile
191 echo `_ ' -> result %s' "$res"` >> $logfile
192 if [ $status -eq 0 ];then
193 amdevcheck_status $tape
200 echo `_ 'Exit ->'` $answer >> $logfile
207 echo " -> info $used" >> $logfile
208 if [ $used -lt 0 ];then
211 answer="$used $lastslot 1"
212 echo `_ 'Exit ->'` $answer >> $logfile
217 echo Args "->" "$@" >> $logfile
218 while [ $# -ge 1 ];do
237 answer=`_ '<none> %s: Unknown option %s' "$myname" "$1"`
238 echo `_ 'Exit ->'` $answer >> $logfile