-# request() {
-# # Send E-mail about the mount request and wait for the drive
-# # to go ready by checking the status once a minute. Repeat
-# # the E-mail once an hour in case it gets lost.
-# timeout=0
-# while true;do
-# if [ $timeout -le 0 ]; then
-# echo "insert Amanda tape into slot $1 ($tape)" \
-# | $MAILER -s "$ORG AMANDA TAPE MOUNT REQUEST FOR SLOT $1" \
-# $REPORTTO
-# timeout=`expr 60 \* 60`
-# fi
-# echo " -> rewind $tape" >> $logfile
-# $MT $MTF $tape rewind >> $logfile 2>&1
-# echo " -> status $tape" >> $logfile
-# used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
-# echo " -> loaded <$used>" >> $logfile
-# if [ ! -z "$used" ];then
-# break
-# fi
-# sleep 60
-# timeout=`expr $timeout - 60`
-# done
-# }
-#
-# Instead of sending mail, you might write the message to /dev/console
-# or use "logger" to send it via syslog, etc.
-###
+request_email() {
+ # Send E-mail about the mount request and wait for the drive
+ # to go ready by checking the status once a minute. Repeat
+ # the E-mail once an hour in case it gets lost.
+ timeout=0
+ gtimeout=$timeout_mail
+ while true;do
+ if [ $gtimeout -le 0 ]; then
+ echo "timeout waiting for tape online"
+ exit 1;
+ fi
+ if [ $timeout -le 0 ]; then
+ msg="insert Amanda tape into slot $1 ($tape)"
+ subject="$ORG AMANDA TAPE MOUNT REQUEST FOR SLOT $1"
+ echo "$msg" | $MAILER -s "$subject" $REPORTTO
+ timeout=$resend_mail
+ fi
+ echo " -> rewind $tape" >> $logfile
+ $MT $MTF $tape rewind >> $logfile 2>&1
+ echo " -> status $tape" >> $logfile
+ used=`$MT $MTF $tape status 2>&1 | tee -a $logfile | $EGREP "$ONLINEREGEX"`
+ echo " -> loaded <$used>" >> $logfile
+ if [ ! -z "$used" ];then
+ break
+ fi
+ sleep 60
+ timeout=`expr $timeout - 60`
+ gtimeout=`expr $gtimeout - 60`
+ done
+}
+request_tty_email() {
+ if > /dev/tty; then
+ echo -n "Insert tape into slot $1 and press return" > /dev/tty
+ read ANSWER < /dev/tty
+ else
+ request_email "$1"
+ fi
+}
+
+request() {
+ if [ X"$request" = X"tty" ]; then
+ request_tty "$1"
+ else if [ X"$request" = X"email" ]; then
+ request_email "$1"
+ else
+ request_tty_email "$1"
+ fi
+ fi
+}