#!/bin/ksh ## ## SCRIPT: host2host_diff_two_files_showBYgui ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: ## For a given pair of Host & FullFilenames names --- ## Host1:FullFilename1 and Host2:FullFilename2 ## ( passed in vars $1, $2, $3, $4 ), ## this script creates a REPORT of ## DIFFERENCES BETWEEN THE TWO FILES. ## ## This utility uses the 'sdiff' command. (or maybe 'diff') ## ----- ## This utility is meant mainly as the 3rd of 3 comparison/difference ## utilities to look for differences in two huge directory ## hierarchies. ## ## The three utilities ## - 'FilCnt,AllSubdirs' ## - 'Diff-Listboxes' ## - 'Diff-Two-Files' ## are briefly described in the help document of the 'xrcp' utility ## /apps/nns_com/fea/helps/host2host_fileman.hlp ## ## This utility ## - 'Diff-Listboxes' ## is meant to be used after the 'first step' utility ## - 'FilCnt,AllSubdirs' ## which reports summary file counts for ALL sub-directories at ## ALL LEVELS under a given directory. That 'FilCnt,AllSubdirs' ## report utility is actually run twice -- for two ## similar directories. ## ## If differences in sub-directory file-counts are found, in that ## 'first step' comparison, ## then one can 'zero in' on specific sub-directories where there ## are differences in counts, with this utility --- to look at ## differences in two lists ## of file-names & file-sizes, for the 2 differing sub-directories. ## ## If files that should be equal in size are different in size, one ## can 'zero in' further, USING THIS SCRIPT/UTILITY, if necessary, ## doing a 'diff' on the two files. ## ## (Or, at this point, one may decide to go ahead and ## equalize the two directory structures.) ############################################################################## ## PROCESSING LOGIC: ## 1) The command 'cat ' is run for the two ## Host:FullFilename pairs. Output is captured in two temp ## files on 'this host', the host running this script. ## ## (We could go back some day, and pipe' at least one ## of the two files into the 'diff' command running on ## 'this host'.) ## ## 2) A report headter is built in a third temporary 'report' file. ## ## 3) An 'sdiff' or 'diff' of the two temporary files is concated ## to the 'report' file. ## ## 4) The report file is shown with 'xpg', running on 'this host'. ## ##--------------------------------------------------------------------------- ## REMOTE HOST NOTE: ## If either 'Host1' or 'Host2' is a remote host, the corresponding ## 'cat' command is run by using 'rsh ': ## rsh cat > ## ##--------------------------------------------------------------------------- ## ## This script puts the report (stdout from the 'sdiff'/'diff' command) ## into a temp-file (on the host running this script) ## and shows the report file with shofil_ver2.tk (the 'xpg' utility). ## ## This script checks for 4 arguments and checks that the pair ## host#:filename# exist. If any of these conditions are not satisfied, ## this script pops an 'xconfirm' error msg and exits. ## ############################################################################## ## CALLED BY: ## host2host_fileman.tk in $FEDIR/tkGUIs ############################################################################## ## ## CALL FORMAT (example): ## ## $FEDIR/scripts/host2host_diff_two_files_showBYgui \ ## engprd00 /apps/autobatch/CRONTAB_CATIA2DIV_cvxprd00 \ ## engprd00 /apps/division_2000i2_aix/autobatch/CRONTAB_CATIA2DIV_cvxprd00 ## ############################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 05dec2001 Based on files-info script ## 'host2host_diff_two_dirs_showBYgui' ## in $FEDIR/scripts ## (includes rmt-dir-existence check). ## Updated by: Blaise Montandon 05dec2001 ############################################################################## THISHOST=`hostname` ############################################################################# ## Set scripts pathname in case this toolchest is not started from ## the nnsFEAmenu system --- and a $FEDIR utility script (or help) is needed. ############################################################################# if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi ############################################################ ## Assure that the DISPLAY variable is set. ## Set to do X-displays on 'this host'. ############################################################ # # if test "${DISPLAY}" = "" # then # DISPLAY="$THISHOST:0" # export DISPLAY # fi ############################################################ ## If this is a remote login, ## set X-display to the 'remote host'. ############################################################ # if test ! "$REMOTEHOST" = "" # then # REMOTEHOST1=`echo $REMOTEHOST | cut -d. -f1` # DISPLAY="$REMOTEHOST1:0" # export DISPLAY # fi ############################################################ ## Set filHOST & FULFILNAME vars using $1 & $2 -- and check ## that they are not null. ############################################################ ## FOR TESTING: # set -x filHOST1="$1" FULFILNAME1="$2" filHOST2="$3" FULFILNAME2="$4" if test "$filHOST1" = "" then xconfirm -c -header "Diff-Two-Files: NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 4 inputs:" \ -t " hostname1 full-filename1 hostname2 full-filename2 ." \ -t "" \ -t "hostname1 was NOT specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi if test "$FULFILNAME1" = "" then xconfirm -c -header "Diff-Two-Files: NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 4 inputs:" \ -t " hostname1 full-filename1 hostname2 full-filename2 ." \ -t "" \ -t "full-filename1 was NOT specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi if test "$filHOST2" = "" then xconfirm -c -header "Diff-Two-Files: NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 4 inputs:" \ -t " hostname1 full-filename1 hostname2 full-filename2 ." \ -t "" \ -t "hostname2 was NOT specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi if test "$FULFILNAME2" = "" then xconfirm -c -header "Diff-Two-Files: NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 4 inputs:" \ -t " hostname1 full-filename1 hostname2 full-filename2 ." \ -t "" \ -t "full-filename2 was NOT specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi ############################################################ ## WARN THE USER THAT THESE SHOULD BE TEXT FILES. ## GIVE THEM A CANCEL OPTION. ############################################################ GO_NOGO=`xconfirm -c -header "Diff-Two-Files: CONFIRM_TEXT_FILES" \ -b CANCEL -B GO \ -t "The files specified" \ -t "" \ -t " $filHOST1 : $FULFILNAME1" \ -t "and" \ -t " $filHOST2 : $FULFILNAME2" \ -t "" \ -t "SHOULD BE TEXT FILES. Are they?" \ -t "" \ -t "This utility is not setup (yet) to handle 'binary data' files," \ -t "like image files ... and data files with floating-point data" \ -t "in easily-machine-readable format, but not easily-human-readable." \ -t "" \ -t "Cancel or Go?" \ -icon warning` # -font $CONFIRM_FONT \ if test "$GO_NOGO" = "CANCEL" then exit fi ############################################################ ## Check that host1:filename1 exists. ## If not, exit with msg. ############################################################ ## File-Existence-Check is broken into two ## mutually-exclusive cases: ## 1) 'specified-host' is 'this-host' ## 2) 'specified-host' is NOT 'this-host' (the case of ## a 'remote-host' file) ############################################################ ############################################################ ## 1) 'specified-host' is 'this-host' ############################################################ if test "$filHOST1" = "$THISHOST" then if test ! -f $FULFILNAME1 then xconfirm -c -header "Diff-Two-Files: FILE_NOT_FOUND_warning" \ -B Dismiss \ -t "The filename $FULFILNAME1 " \ -t "is NOT KNOWN TO host $filHOST1." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test ! -f $FULFILNAME1 fi ## END OF if test "$filHOST1" = "$THISHOST" ############################################################ ## 2) 'specified-host' is NOT 'this-host' ############################################################ if test ! "$filHOST1" = "$THISHOST" then RETcode=`rsh $filHOST1 \ "if test -f $FULFILNAME1 ; then echo 1 ; else echo 0 ; fi"` if test $RETcode = 0 then xconfirm -c -header "Diff-Two-Files: FILE_NOT_FOUND_warning" \ -B Dismiss \ -t "The filename $FULFILNAME1 " \ -t "is NOT KNOWN TO host $filHOST1." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test $RETcode = 0 fi ## END OF if test ! "$filHOST1" = "$THISHOST" ############################################################ ## Check that host2:file2 exists. ## If not, exit with msg. ############################################################ ## File-Existence-Check is broken into two ## mutually-exclusive cases: ## 1) 'specified-host' is 'this-host' ## 2) 'specified-host' is NOT 'this-host' (the case of ## a 'remote-host' file) ############################################################ ############################################################ ## 1) 'specified-host' is 'this-host' ############################################################ if test "$filHOST2" = "$THISHOST" then if test ! -f $FULFILNAME2 then xconfirm -c -header "Diff-Two-Files: FILE_NOT_FOUND_warning" \ -B Dismiss \ -t "The filename $FULFILNAME2 " \ -t "is NOT KNOWN TO host $filHOST2." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test ! -f $FULFILNAME2 fi ## END OF if test "$filHOST2" = "$THISHOST" ############################################################ ## 2) 'specified-host' is NOT 'this-host' ############################################################ if test ! "$filHOST2" = "$THISHOST" then RETcode=`rsh $filHOST2 \ "if test -f $FULFILNAME2 ; then echo 1 ; else echo 0 ; fi"` if test $RETcode = 0 then xconfirm -c -header "Diff-Two-Files: FILE_NOT_FOUND_warning" \ -B Dismiss \ -t "The filename $FULFILNAME2 " \ -t "is NOT KNOWN TO host $filHOST2." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test $RETcode = 0 fi ## END OF if test ! "$filHOST2" = "$THISHOST" ################################################################### ## PREPARE REPORT FILENAME -- in $OUTLIST. ## Also two temp files to hold copies of FULFILENAME1 & FULFILNAME2. ################################################################### . $FEDIR/scripts/set_localoutlist OUTLIST1="${OUTLIST}_1" OUTLIST2="${OUTLIST}_2" ################################################################### ## PUT Host1:File1 in $OUTLIST1. ################################################################### if test "$filHOST1" = "$THISHOST" then ## FOR TESTING: # set -x cat $FULFILNAME1 > $OUTLIST1 ## FOR TESTING: # set - else ## FOR TESTING: # set -x rsh $filHOST1 cat $FULFILNAME1 > $OUTLIST1 ## FOR TESTING: # set - fi ## END OF if test "$filHOST1" = "$THISHOST" ################################################################### ## PUT Host2:File2 in $OUTLIST2. ################################################################### if test "$filHOST2" = "$THISHOST" then ## FOR TESTING: # set -x cat $FULFILNAME2 > $OUTLIST2 ## FOR TESTING: # set - else ## FOR TESTING: # set -x rsh $filHOST2 cat $FULFILNAME2 > $OUTLIST2 ## FOR TESTING: # set - fi ## END OF if test "$filHOST2" = "$THISHOST" ############################################# ## COULD PROMPT THE USER HERE (or below, after ## showing the 'diff' report) ## WHETHER TO USE 'xdiff'. ############################################# ########################################################################## ########################################################################## ## PREPARE THE REPORT -- by running the 'sdiff' command on 'this host' ## with stdout directed to $OUTLIST. But first, prepare a report heading. ########################################################################## ########################################################################## COLWIDTH=93 FILE_LEN=`expr $COLWIDTH - 19` ####################################################### ## PREPARE THE 'DIFF-TWO-FILES' REPORT HEADING. ####################################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** DIFFERENCE BETWEEN TWO (text) FILES File1: ${filHOST1}:$FULFILNAME1 and File2: ${filHOST2}:$FULFILNAME2 File differences are indicated by '<' or '>' or '|' characters between the file-line lists. File lines will be truncated after about $FILE_LEN characters. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- " > $OUTLIST ############################################# ## ADD THE FILE NAMES JUST ABOVE THE COLUMNS. ############################################# echo "File1======>${filHOST1}:$FULFILNAME1 \ File2======>${filHOST2}:$FULFILNAME2" | \ awk '{printf ("%-93s %-93s\n", $1, $2 )}' \ >> $OUTLIST echo " --------------------------------FILE-1-DIFF-LINES-------------------------------------------- -------------------------------FILE-2-DIFF-LINES------------------------------------------------------- " >> $OUTLIST ############################################# ## RUN THE 'sdiff' COMMAND -- 'LOCALLY' ## --- with stdout directed to $OUTLIST. ############################################# # diff $OUTLIST1 $OUTLIST2 >> $OUTLIST TOTWIDTH=`expr $COLWIDTH + $COLWIDTH + 4` sdiff -s -w$TOTWIDTH $OUTLIST1 $OUTLIST2 >> $OUTLIST # sdiff -w$TOTWIDTH $OUTLIST1 $OUTLIST2 >> $OUTLIST ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo " --------------------------------FILE-1-DIFF-LINES-------------------------------------------- -------------------------------FILE-2-DIFF-LINES------------------------------------------------------- ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 ------------- REPORT USAGE: This utility is meant mainly as the 3rd of 3 comparison/difference utilities to look for differences in two huge directory hierarchies. The three utilities - 'FilCnt,AllSubdirs' - 'Diff-Listboxes' - 'Diff-Two-Files' are briefly described in the help document of the 'xrcp' utility /apps/nns_com/fea/helps/host2host_fileman.hlp This utility is 'Diff-Two-Files'. The utility - 'Diff-Listboxes' is meant to be used after the 'first step' utility - 'FilCnt,AllSubdirs' which reports summary file counts for ALL sub-directories at ALL LEVELS under a given directory. That 'FilCnt,AllSubdirs' report utility is actually run twice -- for two similar directories. If differences in sub-directory file-counts are found, in that 'first step' comparison, then one can 'zero in' on specific sub-directories where there are differences in counts, with the 'Diff-Listboxes' utility --- to look at differences in two lists of file-names & file-sizes, for the 2 differing sub-directories. If files that should be equal in size are different in size, one can 'zero in' further, if necessary, using this 'Diff-Two-Files' utility to do a 'diff' on the two files. Or, proceed to 're-equalize' the directory structure. ----------------------------- SELECTING LINES OF THE REPORT -- via a string-pattern: When you browse the report with the 'xpg' utility, you may want to extract/see just those lines that contain a certain string. To do that, you can use the 'ShowAllMatches' button with the plus-or-minus N lines option, with N set to zero (0). Example: To see all lines containing the string '123', put the string '123' (without the quotes) in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. ----------------- PROCESSING METHOD: This report was generated by capturing the output of the Unix command 'cat' for files ${filHOST1}:$FULFILNAME1 and ${filHOST2}:$FULFILNAME2 into two temporary files on $THISHOST . The 'sdiff' command was run on the two temporary files, and the report was assembled-on and presented-from $THISHOST . ---------------------------------------------------------------------------- " >> $OUTLIST ################################################################### ## SHOW the FILE-COUNTS report. ################################################################### $FEDIR/scripts/shofil $OUTLIST