I am comparing multiple files from a directory. Among the files some are matched some are mismatched. I am able to output the difference using diff command. I want to email the mismatched files as attachments.
#!/bin/bash DIR1=/usr/local/apps/B2B/filecompare/inf DIR2=/usr/local/apps/B2B/filecompare/gen/genB DEST_DIR1=/usr/local/apps/B2B/filecompare/moved/cmpinf DEST_DIR2=/usr/local/apps/B2B/filecompare/moved/cmpgen export RESULT=$1 for FILE1 in `ls $DIR1` do if [ ! -f $DIR2/$FILE1 ]; then echo " $FILE1 exists in $DIR1 but not found in $DIR2. Skipping file." >> $RESULT else echo " Comparing $DIR1/$FILE1 $DIR2/$FILE1." >> $RESULT diff -B $DIR1/$FILE1 $DIR2/$FILE1 >> $RESULT #diff $DIR1/$FILE1 $DIR2/$FILE1 >>RESULT echo " Done comparing $DIR1/$FILE1 $DIR2/$FILE1." >> $RESULT mv $DIR1/$FILE1 $DEST_DIR1 mv $DIR2/$FILE1 $DEST_DIR2 echo " Done moving files" >> $RESULT fi done for FILE2 in `ls $DIR2` do if [ ! -f $DIR1/$FILE2 ]; then echo " $FILE2 exists in $DIR2 but not found in $DIR1. Skipping file." >> $RESULT fi done echo " Done comparing." >> $RESULT zip -r $DEST_DIR1/downlaod.zip $DEST_DIR1/$FILE1 $DEST_DIR2/$FILE1 mail -a $DEST_DIR1/downlaod.zip firstname.lastname@example.org