#!/bin/bash

# -----------------------------------------------------------------
# RPC Project :
# Run RPC_zip_cef_database_CLUSTER: zip all cef files in cef data base
# P. Robert, Nov 2020
# -----------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=0

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : zip all cef files in cef data base"
   echo "$appli   require $Narg argument(s)"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datim1=`date +%F'  '%H':'%M':'%S `
julsec1=`date +%s`


echo
echo " -------------------------------------------------------------------"
echo "$appli : zip all cef files in cef data base"
echo "path of cef database: $R_CEF_data_CLU"
echo
find $R_CEF_data_CLU -name "*.cef"   > toto1_$$.tmp
nbfiles=`wc -l toto1_$$.tmp | sed "s/toto1.*//"`

if test $nbfiles = 0 ; then
   echo "there is no cef files to compress"
   rm toto1_$$.tmp
   echo ""
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 0
fi

echo "There is $nbfiles cef files to compress..."
echo "Go!"

sed "s/^/gzip /" toto1_$$.tmp > toto2_$$.tmp
sh toto2_$$.tmp

rm toto1_$$.tmp toto2_$$.tmp

echo done...
echo ""

# end of command
# --------------

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`
diffm=`echo "scale=2; $diff/60." | bc `

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec.  ($diffm mn.)"

echo
echo " $appli36 : NORMAL TERMINATION - time exe= $diff s." >&2

echo " -------------------------------------------------------------------"

