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`
68 if [ -z "$tape" ]; then
69 echo "<none> tapedev not specified in amanda.conf."
73 ORG=`amgetconf$SUF ORG`
78 changerfile=`amgetconf$SUF changerfile`
80 cleanfile=$changerfile-clean
81 accessfile=$changerfile-access
82 slotfile=$changerfile-slot
83 [ ! -f $cleanfile ] && echo 0 > $cleanfile
84 [ ! -f $accessfile ] && echo 0 > $accessfile
85 [ ! -f $slotfile ] && echo $firstslot > $slotfile
86 cleancount=`cat $cleanfile`
87 accesscount=`cat $accessfile`
91 echo "insert tape into slot $1 and press return" >/dev/tty
96 # If $changerfile exists, source it into this script. One reason is to
97 # override the request() function above which gets called to request
98 # that a tape be mounted. Here is an alternate versions of request()
99 # that does things more asynchronous:
102 # # Send E-mail about the mount request and wait for the drive
103 # # to go ready by checking the status once a minute. Repeat
104 # # the E-mail once an hour in case it gets lost.
107 # if [ $timeout -le 0 ]; then
108 # echo "insert Amanda tape into slot $1 ($tape)" \
109 # | $MAILER -s "$ORG AMANDA TAPE MOUNT REQUEST FOR SLOT $1" \
111 # timeout=`expr 60 \* 60`
113 # echo " -> rewind $tape" >> $logfile
114 # $MT $MTF $tape rewind >> $logfile 2>&1
115 # echo " -> status $tape" >> $logfile
116 # used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
117 # echo " -> loaded <$used>" >> $logfile
118 # if [ ! -z "$used" ];then
122 # timeout=`expr $timeout - 60`
126 # Instead of sending mail, you might write the message to /dev/console
127 # or use "logger" to send it via syslog, etc.
130 if [ -f $changerfile ]; then
137 echo " -> rewind $tape" >> $logfile
138 $MT $MTF $tape rewind >> $logfile 2>&1
139 echo " -> status $tape" >> $logfile
140 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
141 echo " -> loaded <$used>" >> $logfile
142 if [ ! -z "$used" ];then
143 echo " -> offline $tape" >> $logfile
144 $MT $MTF $tape offline >> $logfile 2>&1
149 answer="<none> $myname: Drive was not loaded"
152 echo "Exit -> $answer" >> $logfile
160 echo " -> rewind $tape" >> $logfile
161 $MT $MTF $tape rewind >> $logfile 2>&1
162 echo " -> status $tape" >> $logfile
163 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
164 echo " -> loaded <$used>" >> $logfile
165 if [ ! -z "$used" ];then
170 echo "Exit -> $answer" >> $logfile
178 echo " -> rewind $tape" >> $logfile
179 $MT $MTF $tape rewind >> $logfile 2>&1
180 echo " -> status $tape" >> $logfile
181 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
182 echo " -> loaded <$used>" >> $logfile
187 [ $load -eq 0 ] && load=$firstslot
188 [ $load -gt $lastslot ] && load=$firstslot
189 [ $load -lt $firstslot ] && load=$lastslot
192 load=`expr $slot + 1`
193 [ $load -gt $lastslot ] && load=$firstslot
196 load=`expr $slot - 1`
197 [ $load -lt $firstslot ] && load=$lastslot
206 if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
207 answer="<none> $myname: slot must be $firstslot .. $lastslot"
208 echo "Exit -> $answer" >> $logfile
215 answer="<none> $myname: illegal slot: $1"
216 echo "Exit -> $answer" >> $logfile
222 if [ ! -z "$used" -a $load = $slot ];then
225 echo "Exit -> $answer" >> $logfile
230 # if [ $load = $ecleanslot ]; then
231 # expr $cleancount + 1 > $cleanfile
232 # echo 0 > $accessfile
234 expr $accesscount + 1 > $accessfile
235 # if [ $accesscount -gt 9 ]; then
236 # $myname -slot $cleanslot >/dev/null
242 if [ ! -z "$used" ]; then
243 echo " -> offline $tape" >> $logfile
244 $MT $MTF $tape offline >> $logfile 2>&1
247 if [ $whichslot = advance ]; then
250 echo " -> load $load" >> $logfile
251 while [ -z "$used" ]; do
253 echo " -> rewind $tape" >> $logfile
254 $MT $MTF $tape rewind >> $logfile 2>&1
255 echo " -> status $tape" >> $logfile
256 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
257 echo " -> loaded <$used>" >> $logfile
259 $DD if=$tape bs=32k count=1 >> $logfile 2>&1
261 echo $load > $slotfile
263 echo "Exit -> $answer" >> $logfile
271 echo " -> rewind $tape" >> $logfile
272 $MT $MTF $tape rewind >> $logfile 2>&1
273 echo " -> status $tape" >> $logfile
274 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
275 echo " -> loaded <$used>" >> $logfile
276 if [ -z "$used" ];then
277 answer="0 $lastslot 1"
279 answer="$slot $lastslot 1"
281 echo "Exit -> $answer" >> $logfile
290 echo Args "->" "$@" >> $logfile
291 while [ $# -ge 1 ];do
310 echo "<none> $myname: Unknown option $1"