All pastes #126615 Raw Edit

Stuff

public text v1 · immutable
·published 2006-08-11 17:23 UTC
rendered paste body
#
#---- cg_filecomp - Quickly check to see if the contents of 2 files
#
#---- Usage: See cg_filecomp_helpme below
#
#---- Example:  cg_filecomp popo1.jpg popo1.last.jpg
#
#---- Returns:  1 - Files are the same
#               2 - Files are different
#               3 - error   
 
declare -i file1size
declare -i file2size

########################
#   LOCAL FUNCTIONS    #
########################

cg_filecomp_helpme () {

cat<<EOD

cg_filecomp - Quickly check to see if the contents of 2 files
Usage: cg_filecomp file1 file2   
Example: cg_filecomp Yin Yang 

Note that base_directory must be a subdirectory of the environment directory CAPTURE_DIR <$CAPTURE_DIR>

To stop execution run $CAPTURE_DIR/$PROGNAME.stop.sh

To change the update rate modify $CAPTURE_DIR/$PROGNAME.updrate

EOD

}

cg_filecomp () {

if [ $# -ne 2 ]
then
  echo "*** ERROR *** - Number of arguments $# is incorrect"
  cg_filecomp_helpme
  echo "Aborting... "
  RC="3"
  return $RC
fi # [ $# -ne 2 ]

if [ ! -f $1 ]
then
  echo "*** WARNING *** - File 1 <$1> does not exist"
#  cg_filecomp_helpme
#  echo "Aborting... "
  RC="3"
  return $RC
fi #  [ ! -f $` ]
  
file1=$1

if [ ! -f $2 ]
then
  echo "*** WARNING *** - File 2 <$2> does not exist"
#  cg_filecomp_helpme
#  echo "Aborting... "
  RC="3"
  return $RC
fi #  [ ! -f $2 ]
  
file2=$2

cg_filecomp_file1size="`ls -l $file1|awk '{print $5}'`"
cg_filecomp_file2size="`ls -l $file2|awk '{print $5}'`"


if [ $cg_filecomp_file1size -ne $cg_filecomp_file2size ]
then
#  echo "Different sizes"
  RC="2"
  return $RC
fi

cg_filecomp_file1md5sum="`md5sum $file1|awk '{print $1}'`"
cg_filecomp_file2md5sum="`md5sum $file2|awk '{print $1}'`"

if [ $cg_filecomp_file1md5sum != $cg_filecomp_file2md5sum ]
then
#  echo "$file1 and $file2 have different md5"
  RC="2"
  return $RC
fi

#echo "Files are Same"
RC="1"
return $RC

}