#! /bin/sh

# $Id: cloning_summary,v 1.3 2009/07/29 14:36:21 zalokar Exp $

#Make tables showing the progress of cloning (or squeezing) tapes.

#Get all the common stuff for migration, duplication and cloning reporting.
source migration_common

#Create the variables that point to the files to output to.
fname=CLONING_SUMMARY
output_file=$inventory_dir/$fname
temp_file=$temp_dir/$fname.temp

#If we write to a temp file, and swap in it when we are done, there will
# not any time when the page is empty becuase the scipt is still writing
# the file.
rm -f $temp_file

#Make sure we know how up-to-date this is.
echo -e Cloning Report: `date` > $temp_file 2>&1
echo -e Brought to You by: `basename $0` "\n" >> $temp_file 2>&1


echo                   >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo "Cloning per Day" >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo                   >> $temp_file 2>&1

echo "Creating Cloning per Day" `date`

cloning_per_day >> $temp_file 2>&1

echo                     >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo "Cloning History" >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo                     >> $temp_file 2>&1

echo "Creating Cloning History" `date`

cloning_history >> $temp_file 2>&1

mv "$temp_file" "$output_file" #Do the temp file swap.

#For backward compatiblity make an html file too.
echo Starting to making html file for cloning.
rm -f $output_file.html
cat << EOF >> $output_file.html
<html> <head> <title>$tl_name Cloning Summary Page</title> </head>
<body>
<body bgcolor="#ffffff" text=#a0a0ff">
<meta http-equiv="Refresh" content="900">
<hr>
<pre>
EOF

    #We need to add a link to the web page with the plots on it.
    link="<a href=$url_dir/migration_summary/plot_enstore_system.html>Cloning Summary Plots</a>"

    #The following sed is used more like cat to append $output_file
    # to $output_file.html.  The fancy sed part just inserts the link
    # on line 3 in the process of "cat"ing the file.
    sed "3s;\(.*\);${link}\n\1;" $output_file >> $output_file.html

    echo >> $output_file.html
    echo ${link} >> $output_file.html
    echo >> $output_file.html

    cat << EOF >> $output_file.html
</pre>
<hr>
<hr>
</body>
EOF
