X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fchg-manual.sh.in;h=1c45651688456ad18e40e9b1574dc9d4b095317c;hb=d3b2175e084f88c8736ad7073eacbf4670147aec;hp=205decfae4c2f2742e3ca7464fe5c5a05f65bd3e;hpb=34197d9f46a5f4e944378cbb65fca32ee0eec7b9;p=debian%2Famanda diff --git a/changer-src/chg-manual.sh.in b/changer-src/chg-manual.sh.in index 205decf..1c45651 100644 --- a/changer-src/chg-manual.sh.in +++ b/changer-src/chg-manual.sh.in @@ -15,6 +15,19 @@ libexecdir=@libexecdir@ PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb export PATH +# +# Changer config file (changerfile) +# +# resend_mail=900 # 15 minutes +# timeout_mail=604800 # 7 days +# request="tty" # Use the tty to ask the user to change tape. +# # Can't be use by cron +# request="email" # Send an email to ask the user to change tape. +# request="tty_email" # Use the tty if it exist or send an email. +# #Default is "tty_email" +# +# + if [ -d "@AMANDA_DBGDIR@" ]; then logfile=@AMANDA_DBGDIR@/changer.debug else @@ -74,9 +87,19 @@ ORG=`amgetconf$SUF ORG` firstslot=1 lastslot=99 +resend_mail=900 # 15 minutes +timeout_mail=604800 # 7 days changerfile=`amgetconf$SUF changerfile` +conf_match=`expr "$changerfile" : .\*\.conf\$` +if [ $conf_match -ge 6 ]; then + configfile=$changerfile + changerfile=`echo $changerfile | sed 's/.conf$//g'` +else + configfile=$changerfile.conf +fi + cleanfile=$changerfile-clean accessfile=$changerfile-access slotfile=$changerfile-slot @@ -87,48 +110,75 @@ cleancount=`cat $cleanfile` accesscount=`cat $accessfile` slot=`cat $slotfile` -request() { - echo "insert tape into slot $1 and press return" >/dev/tty - read ANSWER /dev/tty; then + echo -n "Insert tape into slot $1 and press return" > /dev/tty + read ANSWER < /dev/tty + else + echo "no /dev/tty to ask to change tape" + exit 1 + fi } + ### # If $changerfile exists, source it into this script. One reason is to # override the request() function above which gets called to request # that a tape be mounted. Here is an alternate versions of request() # that does things more asynchronous: # -# 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 +} -if [ -f $changerfile ]; then - . $changerfile +if [ -f $configfile ]; then + . $configfile fi # @@ -142,7 +192,6 @@ eject() { if [ ! -z "$used" ];then echo " -> offline $tape" >> $logfile $MT $MTF $tape offline >> $logfile 2>&1 - echo 0 > $slotfile answer="$slot $tape" code=0 else