Subject: Script to run ontape unattended for multi-tape backup
From: "Peter Tashkoff" <[email-masked]>
Date: Thu, 15 Jan 1998 15:20:04 +1300

Hello People.
Another candidate for the software archives if you think it fit.

This script will run ontape unattended against a jukebox drive, cycling
the tapes as required.

rgds
Peter Tashkoff
Marketing Database Systems Ltd

#!/bin/ksh
#Usage: auto_ontape.sh | ontape -s > /tmp/auto_ontape.log
#Methodology: Ontape writes out to standard output when it
#             wants a new tape.  By redirecting this
#             and reading the output, it is possible
#             for ythis script to react at the 
#             correct moment to advance the jukebox
#             to a new tape, and then advise ontape
#             to continue.
#             Tested and proven on Solaris 2.5
#             Standard SUN Jukebox drive.
#             Script may require minor amendment for other
#             systems.
#--------------------------------------------------------

#Send a zero to ontape for archive level
echo "0"
#send an additional carriage return for 'Mount tape 1,any key to continue'
echo 

#The log will have the request to mount a tape on the last line.
#Since it will already be mounted, we do not want the check in
#the while loop (below) to trigger a cycling of the tape,
#So put some garbage on the last line of the log.
echo "\n first Time in \n" >>/tmp/auto_ontape.log

#This checks the log every minute to see if ontape
#is asking for a new tape.  If it is then the
#jukebox is advanced to the next tape, and ontape
#then is advised to continue with the backup.
#A 120 second pause occurs to allow time for the drive
#to advance.  An alternative would be to use the 'mt' command
#to check status, if 120 seconds is a bother to anyone.
while true
do
    sleep 60 # check every minute to see if ontape wants a new tape
    CHECK=`tail -1 /tmp/auto_ontape.log | awk '{print $2}'`
    if [ $CHECK == "mount" ]
    then
	   mt -f /dev/rmt/0 offline
       sleep 120 #Give the tape time to cycle
	   #This echo means that the 'mount' keyword will no
	   #longer be on the last line of the log.
	   echo "\n Tape has been changed \n" >> /tmp/auto_ontape.log
	   echo #Carriage return to advise online that tape has changed
    fi

    #This check is never struck as the script will die when ontape
	#finishes.
    if [ $CHECK == "over." ]
	then
	   exit
	fi

done