ANSI tape files to disk

#! /bin/sh
#--------------------------------------------------------
# script for retreiving listmode data files from tape
# to disk
# Matthias Schlett and Andreas Wagner
# Forschungszentrum Dresden-Rossendorf e.V.
# Postfach 510119, 01324 Dresden, Germany
#--------------------------------------------------------
# following tape drives make some sense:
# dlt1 is connected to eva2 directly
# exa1 is connected to eva2 directly
# exa2 is connected to the fibrechannel adaptor
#--------------------------------------------------------
# preparing directory
dir="/gfs/data/nuclei/lmd/jun03"
dir="/gfs/data/nuclei/lmd/mar04"
q=""
while [ -z "$q" ]
do
echo " Enter target directory for file storage: [$dir]"
read ans
if [ x"$ans" != x ]; then dir="$ans" ; fi
if [ -d $dir ]; then q=y
else echo directory $dir does not exist
fi
done

#preparing the tape
tape="exa2"
while [ -z "$query" ]
do
echo "Enter the name of the tape drive [$tape]"
read answer
case "$answer" in
[d][l][t]?)
tape="$answer"
query="y"
;;
[e][x][a]?)
tape="$answer"
query="y"
;;
"" )
query="y"
;;
*) echo " exa? or dlt? "
esac
done

status="`mt -f /dev/$tape status `"
while [ -z "$status" ]
do
echo "Tape /dev/$tape not ready "
while [ -z "$query" ]
do
echo "Enter the name of the tape drive [$tape]"
read answer
case "$answer" in
[d][l][t]?)
tape="$answer"
query="y"
;;
[e][x][a]?)
tape="$answer"
query="y"
;;
*) echo " exa? or dlt? "
esac
done

status="`mt -f /dev/$tape status|grep ONLINE `"
if [ -z "$status" ] ; then query="" ; fi
# block="`mt -f /dev/$tape status|grep block|awk '{print $4}'`"
#if [ "$block" != 0 ] ; then mt -f /dev/$tape setblk 0 ; fi
done
mt -f /dev/$tape setblk 0

/bin/echo "STATUS of tape $tape :"
/bin/echo " `mt -f /dev/$tape status` "
echo " Tape /dev/$tape ready: Please wait until rewind has finished"

mt -f /dev/$tape rewind

# Tape ready
j=""

# loop for all files

while [ -z "$j" ]
do
# read file header
dd if=/dev/$tape of=t$$ bs=80
blk="`sed -e "s/HDR2F/:/" t$$ |awk -F: '{print $2}' | awk '{print substr($1,
1,length($1)/2)}'`" file="`sed -e "s/HDR1/:/" t$$ |awk -F: '{print $2}' | awk '{print $1}' | tr
'[A-Z]' '[a-z]' `" if [ x"$file" = x ] ; then echo File header empty, end of tape reached. Now
you may quit else echo Next file $file has blocksize $blk
fi

# store or skip the file, or quit
q=""
while [ -z "$q" ]
do
echo "Do you want to store the data file $file (y/n/q): [y] "
read answer
case "$answer" in
[yYaA]* | "" ) q="y"
# reading data file
if [ ! -f $dir/$file ] ; then echo "Copying file $file to the direct
ory $dir " dd if=/dev/$tape of=$dir/$file bs=$blk
else
echo "File $dir/$file exists, enter a new file name (name.lmd) "
qq=""
while [ -z "$qq" ]
do
read ans
case "$ans" in
*.lmd)
if [ -f $dir/$ans ] ; then echo File $dir/$ans already exist
s else
qq="y"
fi
;;
*) echo No .lmd file
;;
esac
done
dd if=/dev/$tape of=$dir/$ans bs=$blk
fi
# reading tail file
dd if=/dev/$tape of=t$$ bs=80
;;

[nN]*) q="y"
echo "Skipping file $file "
mt -f /dev/$tape fsf 2
;;
[qQ] ) j="end"
rm t$$ ; exit 0
;;
*) q=""
;;
esac
done
# Loop
done
echo This END should not be reached