#! /bin/bash #+ # NAME: # compare_tree # PURPOSE: # Compare content of directory tree # OPTIONAL INPUT PARAMETERS: # $1 source directory; default: $PWD # $2 destination directory: default: $OLDPWD # SEE ALSO: # fcdir # PROCEDURE: # Topdirectories should have a trailing / # # All files in $1 are compared to files in $2 with the same name. # MODIFICATION HISTORY: # ???-????, Paul Hick (UCSD/CASS; pphick@ucsd.edu) #- if [ "$1" == "-rm" ]; then shift action=1 elif [ "$1" == "-gz" ]; then shift action=2 elif [ "$1" == "-ssh" ]; then shift action=3 elif [ "$1" == "-mv" ]; then shift action=4 else action=0 fi if [ -n "$1" ]; then topdir1=$1/ else topdir1="." fi if [ -n "$2" ]; then topdir2=$2/ else topdir2=".." fi all=$TUB/compare_tree_all.txt tmp=$TUB/compare_tree_tmp.txt echo "Source directory: $topdir1" echo "Comparison directory: $topdir2" ls -1ARp $topdir1 > $all cat $all | while read line; do # A line containing a directory is identified by a trailing colon. # First test for a colon. If present, make sure it's trailing. echo $line | grep ":" > $tmp colon=$? if [ $colon = 0 ]; then trail=$(cat $tmp | gawk -F : '{print $2}') else trail="xxx" fi if [ "$trail" = "" ]; then # Extract the directory (preceding :). This directory will not # have a trailing / unless it is the root. # Append the trailing / if it's not the root. found=$(cat $tmp | gawk -F : '{print $1}') if [ "$found" != "/" ]; then found=$found/ fi echo $found > $tmp # Extract the part following topdir1. # For topdir1 itself this is the null string, otherwise it is # a subdirectory (no leading /), with a trailing / present. found=$(cat $tmp | gawk -F $topdir1 '{print $2}') echo Directory: $topdir1$found elif [ "$line" != "" ]; then # Intercept symbolic links and strip of the trailing @. echo $line | grep "@" > $tmp if [ $? = 0 ]; then line=$(cat $tmp | gawk -F @ '{print $1}') fi # Relative filename (no leading /). line=$found$line if [ -f "$topdir1$line" ]; then if [ -f "$topdir2$line" ]; then #diff "$topdir1$line" "$topdir2$line" > /dev/null 2> /dev/null diff "$topdir1$line" "$topdir2$line" status=$? if [ $status = 1 ]; then echo $topdir1$line: different elif [ $status = 2 ]; then echo $topdir1$line: trouble else echo $topdir1$line: identical if [ $action == 1 ]; then rm -v "$topdir1$line" elif [ $action == 2 ]; then gzip -v "$topdir1$line" if [ -d "$3" ]; then mv -v "$topdir1$line.gz" $3 fi elif [ $action == 3 ]; then ziggy \"gzip -v "$topdir1$line"\" if [ -d "$3" ]; then mv -v "$topdir1$line.gz" $3 fi fi fi else echo $topdir1$line: no match if [ $action == 4 ]; then mv -v "$topdir1$line" "$topdir2$line" fi fi fi fi done rm -f $all $tmp exit 0