Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 dec2004.tar

Listing 8 list_changed.sh

#!/bin/ksh

#**************************************************************
# Listing 8:
# File: list_changed.sh
#
# Description:
#
# This script takes a file generated by the compare command and
# lists the files that were modified.
#
# Author: John Spurgeon (john.p.spurgeon@intel.com)
#
#**************************************************************

if [ "$#" -ne 3 ]
then
   echo "[$(basename $0)] usage: $(basename $0) FILE LABEL1 LABEL2" >& 2
   exit 1
fi

FILE=$1
LABEL1=$2
LABEL2=$3

if ! [ -f $FILE ]
then
   echo "[$(basename $0)] Error: $FILE does not exist!" >& 2
   exit 1
fi

awk 'BEGIN {
   last = ""
   buffer = ""
   n = 0
   cn_string = "-,-,i-node number:,mode:,links:,owner:,group:,size in \
                bytes:,last modified:,/usr/bin/md5:,/usr/bin/sum:, \
                /usr/ucb/sum:,/usr/bin/cksum:"
   split(cn_string, col_names, ",")
   format="%20s %-35s %-35s\n"
}
{
   if ($1 == ">" && buffer != "") {
      if ($2 == last) {
         if (n > 0) {
            printf "\n"
         }
         print $2
         printf(format, "snapshot:", SNAPSHOT_LHS, SNAPSHOT_RHS)
         cols_b = split(buffer, lhs)
         cols_c = split($0, rhs)
         if (cols_b != cols_c) {
            print "FUBAR!"
         }
         else {
            cols = cols_b
         }
         for (i=2; i <= cols; i++) {
            if (lhs[i] != rhs[i]) {
               printf(format, col_names[i], lhs[i], rhs[i])
            }
         }
         n++
      }
      buffer = ""
   }
   if ($1 == "<") {
      buffer = $0
   }
      last = $2
}' SNAPSHOT_LHS=$LABEL1 SNAPSHOT_RHS=$LABEL2 $FILE


#!/bin/ksh