Error in Backup Script

Hi,

I made a following script for Data Backup on Tape Device, but script is not working fine. Please review the script.

DAT=`date +%d_%m_%Y`
BDIR="/home/userid/$DAT"
TD="/dev/st0"
LOGS="/scripts/$DAT"
 
clear
echo | tee $LOGS
 
if mt -f $TD status | grep 41010000 > /dev/null
then
echo "Tape Found in DRIVE" | tee -a $LOGS
 
mt -f $TD load
 
if test $? = 0
then
echo "Tape loaded successfully"
echo | tee -a $LOGS
 
SIZE=`du -sh $BDIR | cut -f1`
echo "Size of $DAT Directory: $SIZE" | tee -a $LOGS
echo | tee -a $LOGS
 
time_start=`date +%s`
echo "BACKUP START at" `date` | tee -a $LOGS
echo
 
tar -cvp -f $TD $BDIR | tee -a $LOGS
 
mt -f $TD offline
        if test $? = 0
        then
        echo "Tape unloaded sucessfully"
        else
        echo "Unloading Tape failed. Check it manually"
        fi
 
echo
else
echo "          Cartridge not found in DRIVE1"
echo "          Please Insert Cartridge in DRIVE1 Only"
sleep 6
exit 2
fi
echo | tee -a $LOGS
 
time_end=`date +%s`
time_elapsed=$((time_end - time_start))
echo "BACKUP FINISHED at" `date` | tee -a $LOGS
echo | tee -a $LOGS
echo "Backup Completed Time $(( time_elapsed / 60 )) Minute $(( time_elapsed % 60 )) Seconds" | tee -a $LOGS
echo | tee -a $LOGS
 
echo
read -p "Press Enter to continue.........." readDamKey
 
exit 0

Mind sharing in detail what is not working well before one has to check the whole code? Might be easier, ty.

... and which Operating System and Shell you are using.

First impressions are of syntax errors. For example there are 3 "if" but only 2 "fi".
There probably should be a "fi" just before the "else".
Indentation is your friend.

To check for syntax errors before running a script (assuming ksh):

ksh -n scriptname

Though in your case it probably doesn't matter it is normal to use the "no rewind" device in "mt" commands.
Not sure what sort of tape deck this is but I have never seen a "mt load" command and have never needed a "mt offline" command. The "mt status" and "mt rewind" are usually what you need.

I am using Oracle Enterprise & script based on bash shell