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
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
35 if [ -x $sbindir/ammt$SUF ]; then
38 elif [ -x "@MT@" ]; then
42 answer="<none> $myname: mt program not found"
44 echo "Exit -> $answer" >> $logfile
48 echo MT "->" $MT $MTF >> $logfile
50 if [ -x $sbindir/amdd$SUF ]; then
52 elif [ -x "@DD@" ]; then
55 answer="<none> $myname: dd program not found"
57 echo "Exit -> $answer" >> $logfile
61 echo DD "->" $DD >> $logfile
64 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
65 REPORTTO=`amgetconf$SUF mailto`
66 tape=`amgetconf$SUF tapedev`
67 ORG=`amgetconf$SUF ORG`
72 changerfile=`amgetconf$SUF changerfile`
74 cleanfile=$changerfile-clean
75 accessfile=$changerfile-access
76 slotfile=$changerfile-slot
77 [ ! -f $cleanfile ] && echo 0 > $cleanfile
78 [ ! -f $accessfile ] && echo 0 > $accessfile
79 [ ! -f $slotfile ] && echo $firstslot > $slotfile
80 cleancount=`cat $cleanfile`
81 accesscount=`cat $accessfile`
85 echo "insert tape into slot $1 and press return" >/dev/tty
90 # If $changerfile exists, source it into this script. One reason is to
91 # override the request() function above which gets called to request
92 # that a tape be mounted. Here is an alternate versions of request()
93 # that does things more asynchronous:
96 # # Send E-mail about the mount request and wait for the drive
97 # # to go ready by checking the status once a minute. Repeat
98 # # the E-mail once an hour in case it gets lost.
101 # if [ $timeout -le 0 ]; then
102 # echo "insert Amanda tape into slot $1 ($tape)" \
103 # | $MAILER -s "$ORG AMANDA TAPE MOUNT REQUEST FOR SLOT $1" \
105 # timeout=`expr 60 \* 60`
107 # echo " -> rewind $tape" >> $logfile
108 # $MT $MTF $tape rewind >> $logfile 2>&1
109 # echo " -> status $tape" >> $logfile
110 # used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
111 # echo " -> loaded <$used>" >> $logfile
112 # if [ ! -z "$used" ];then
116 # timeout=`expr $timeout - 60`
120 # Instead of sending mail, you might write the message to /dev/console
121 # or use "logger" to send it via syslog, etc.
124 if [ -f $changerfile ]; then
131 echo " -> rewind $tape" >> $logfile
132 $MT $MTF $tape rewind >> $logfile 2>&1
133 echo " -> status $tape" >> $logfile
134 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
135 echo " -> loaded <$used>" >> $logfile
136 if [ ! -z "$used" ];then
137 echo " -> offline $tape" >> $logfile
138 $MT $MTF $tape offline >> $logfile 2>&1
143 answer="<none> $myname: Drive was not loaded"
146 echo "Exit -> $answer" >> $logfile
154 echo " -> rewind $tape" >> $logfile
155 $MT $MTF $tape rewind >> $logfile 2>&1
156 echo " -> status $tape" >> $logfile
157 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
158 echo " -> loaded <$used>" >> $logfile
159 if [ ! -z "$used" ];then
164 echo "Exit -> $answer" >> $logfile
172 echo " -> rewind $tape" >> $logfile
173 $MT $MTF $tape rewind >> $logfile 2>&1
174 echo " -> status $tape" >> $logfile
175 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
176 echo " -> loaded <$used>" >> $logfile
181 [ $load -eq 0 ] && load=$firstslot
182 [ $load -gt $lastslot ] && load=$firstslot
183 [ $load -lt $firstslot ] && load=$lastslot
186 load=`expr $slot + 1`
187 [ $load -gt $lastslot ] && load=$firstslot
190 load=`expr $slot - 1`
191 [ $load -lt $firstslot ] && load=$lastslot
200 if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
201 answer="<none> $myname: slot must be $firstslot .. $lastslot"
202 echo "Exit -> $answer" >> $logfile
209 answer="<none> $myname: illegal slot: $1"
210 echo "Exit -> $answer" >> $logfile
216 if [ ! -z "$used" -a $load = $slot ];then
219 echo "Exit -> $answer" >> $logfile
224 # if [ $load = $ecleanslot ]; then
225 # expr $cleancount + 1 > $cleanfile
226 # echo 0 > $accessfile
228 expr $accesscount + 1 > $accessfile
229 # if [ $accesscount -gt 9 ]; then
230 # $myname -slot $cleanslot >/dev/null
236 if [ ! -z "$used" ]; then
237 echo " -> offline $tape" >> $logfile
238 $MT $MTF $tape offline >> $logfile 2>&1
241 if [ $whichslot = advance ]; then
244 echo " -> load $load" >> $logfile
245 while [ -z "$used" ]; do
247 echo " -> rewind $tape" >> $logfile
248 $MT $MTF $tape rewind >> $logfile 2>&1
249 echo " -> status $tape" >> $logfile
250 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
251 echo " -> loaded <$used>" >> $logfile
253 $DD if=$tape bs=32k count=1 >> $logfile 2>&1
255 echo $load > $slotfile
257 echo "Exit -> $answer" >> $logfile
265 echo " -> rewind $tape" >> $logfile
266 $MT $MTF $tape rewind >> $logfile 2>&1
267 echo " -> status $tape" >> $logfile
268 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
269 echo " -> loaded <$used>" >> $logfile
270 if [ -z "$used" ];then
271 answer="0 $lastslot 1"
273 answer="$slot $lastslot 1"
275 echo "Exit -> $answer" >> $logfile
284 echo Args "->" "$@" >> $logfile
285 while [ $# -ge 1 ];do
304 echo "<none> $myname: Unknown option $1"