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
19 # Changer config file (changerfile)
21 # resend_mail=900 # 15 minutes
22 # timeout_mail=604800 # 7 days
23 # request="tty" # Use the tty to ask the user to change tape.
24 # # Can't be use by cron
25 # request="email" # Send an email to ask the user to change tape.
26 # request="tty_email" # Use the tty if it exist or send an email.
27 # #Default is "tty_email"
31 if [ -d "@AMANDA_DBGDIR@" ]; then
32 logfile=@AMANDA_DBGDIR@/changer.debug
37 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
38 if test "$USE_VERSION_SUFFIXES" = "yes"; then
48 if [ -x $sbindir/ammt$SUF ]; then
51 elif [ -x "@MT@" ]; then
55 answer="<none> $myname: mt program not found"
57 echo "Exit -> $answer" >> $logfile
61 echo MT "->" $MT $MTF >> $logfile
63 if [ -x $sbindir/amdd$SUF ]; then
65 elif [ -x "@DD@" ]; then
68 answer="<none> $myname: dd program not found"
70 echo "Exit -> $answer" >> $logfile
74 echo DD "->" $DD >> $logfile
77 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
78 REPORTTO=`amgetconf$SUF mailto`
79 tape=`amgetconf$SUF tapedev`
81 if [ -z "$tape" ]; then
82 echo "<none> tapedev not specified in amanda.conf."
86 ORG=`amgetconf$SUF ORG`
90 resend_mail=900 # 15 minutes
91 timeout_mail=604800 # 7 days
93 changerfile=`amgetconf$SUF changerfile`
95 conf_match=`expr "$changerfile" : .\*\.conf\$`
96 if [ $conf_match -ge 6 ]; then
97 configfile=$changerfile
98 changerfile=`echo $changerfile | sed 's/.conf$//g'`
100 configfile=$changerfile.conf
103 cleanfile=$changerfile-clean
104 accessfile=$changerfile-access
105 slotfile=$changerfile-slot
106 [ ! -f $cleanfile ] && echo 0 > $cleanfile
107 [ ! -f $accessfile ] && echo 0 > $accessfile
108 [ ! -f $slotfile ] && echo $firstslot > $slotfile
109 cleancount=`cat $cleanfile`
110 accesscount=`cat $accessfile`
115 echo -n "Insert tape into slot $1 and press return" > /dev/tty
116 read ANSWER < /dev/tty
118 echo "no /dev/tty to ask to change tape"
125 # If $changerfile exists, source it into this script. One reason is to
126 # override the request() function above which gets called to request
127 # that a tape be mounted. Here is an alternate versions of request()
128 # that does things more asynchronous:
131 # Send E-mail about the mount request and wait for the drive
132 # to go ready by checking the status once a minute. Repeat
133 # the E-mail once an hour in case it gets lost.
135 gtimeout=$timeout_mail
137 if [ $gtimeout -le 0 ]; then
138 echo "timeout waiting for tape online"
141 if [ $timeout -le 0 ]; then
142 msg="insert Amanda tape into slot $1 ($tape)"
143 subject="$ORG AMANDA TAPE MOUNT REQUEST FOR SLOT $1"
144 echo "$msg" | $MAILER -s "$subject" $REPORTTO
147 echo " -> rewind $tape" >> $logfile
148 $MT $MTF $tape rewind >> $logfile 2>&1
149 echo " -> status $tape" >> $logfile
150 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
151 echo " -> loaded <$used>" >> $logfile
152 if [ ! -z "$used" ];then
156 timeout=`expr $timeout - 60`
157 gtimeout=`expr $gtimeout - 60`
160 request_tty_email() {
162 echo -n "Insert tape into slot $1 and press return" > /dev/tty
163 read ANSWER < /dev/tty
170 if [ X"$request" = X"tty" ]; then
172 else if [ X"$request" = X"email" ]; then
175 request_tty_email "$1"
180 if [ -f $configfile ]; then
187 echo " -> rewind $tape" >> $logfile
188 $MT $MTF $tape rewind >> $logfile 2>&1
189 echo " -> status $tape" >> $logfile
190 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
191 echo " -> loaded <$used>" >> $logfile
192 if [ ! -z "$used" ];then
193 echo " -> offline $tape" >> $logfile
194 $MT $MTF $tape offline >> $logfile 2>&1
198 answer="<none> $myname: Drive was not loaded"
201 echo "Exit -> $answer" >> $logfile
209 echo " -> rewind $tape" >> $logfile
210 $MT $MTF $tape rewind >> $logfile 2>&1
211 echo " -> status $tape" >> $logfile
212 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
213 echo " -> loaded <$used>" >> $logfile
214 if [ ! -z "$used" ];then
219 echo "Exit -> $answer" >> $logfile
227 echo " -> rewind $tape" >> $logfile
228 $MT $MTF $tape rewind >> $logfile 2>&1
229 echo " -> status $tape" >> $logfile
230 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
231 echo " -> loaded <$used>" >> $logfile
236 [ $load -eq 0 ] && load=$firstslot
237 [ $load -gt $lastslot ] && load=$firstslot
238 [ $load -lt $firstslot ] && load=$lastslot
241 load=`expr $slot + 1`
242 [ $load -gt $lastslot ] && load=$firstslot
245 load=`expr $slot - 1`
246 [ $load -lt $firstslot ] && load=$lastslot
255 if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
256 answer="<none> $myname: slot must be $firstslot .. $lastslot"
257 echo "Exit -> $answer" >> $logfile
264 answer="<none> $myname: illegal slot: $1"
265 echo "Exit -> $answer" >> $logfile
271 if [ ! -z "$used" -a $load = $slot ];then
274 echo "Exit -> $answer" >> $logfile
279 # if [ $load = $ecleanslot ]; then
280 # expr $cleancount + 1 > $cleanfile
281 # echo 0 > $accessfile
283 expr $accesscount + 1 > $accessfile
284 # if [ $accesscount -gt 9 ]; then
285 # $myname -slot $cleanslot >/dev/null
291 if [ ! -z "$used" ]; then
292 echo " -> offline $tape" >> $logfile
293 $MT $MTF $tape offline >> $logfile 2>&1
296 if [ $whichslot = advance ]; then
299 echo " -> load $load" >> $logfile
300 while [ -z "$used" ]; do
302 echo " -> rewind $tape" >> $logfile
303 $MT $MTF $tape rewind >> $logfile 2>&1
304 echo " -> status $tape" >> $logfile
305 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
306 echo " -> loaded <$used>" >> $logfile
308 $DD if=$tape bs=32k count=1 >> $logfile 2>&1
310 echo $load > $slotfile
312 echo "Exit -> $answer" >> $logfile
320 echo " -> rewind $tape" >> $logfile
321 $MT $MTF $tape rewind >> $logfile 2>&1
322 echo " -> status $tape" >> $logfile
323 used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
324 echo " -> loaded <$used>" >> $logfile
325 if [ -z "$used" ];then
326 answer="0 $lastslot 1"
328 answer="$slot $lastslot 1"
330 echo "Exit -> $answer" >> $logfile
339 echo Args "->" "$@" >> $logfile
340 while [ $# -ge 1 ];do
359 echo "<none> $myname: Unknown option $1"