Hi
I have a script which unzips a list of files from a tar to a temp directory.
I now need to compare/diff on each unzipped file with the one in its original source directory.
Not sure where to start even, can find the files withe same file name in the source directory but not sure what to do next.
for i in `ls`;do find $IMPORTANT_FILES_DIRECTORY -name $i; done
Can i do an && and something like below? How would I do it with two lists of files in two directories?
for i in `ls`;
do
[[ find $IMPORTANT_FILES_DIRECTORY -name $i ]] | if diff $1 file2 >/dev/null ; then
echo Same
else
echo Different
fi;
done
Code:
#!/bin/bash
BASEDIR=$(cd `dirname $0` && pwd)
CONFILE=$BASEDIR/confile.cfg
BACKUP_FILES=$HOME/assignment1/backups
RESTORE_COMP_DIRECTORY=$HOME/assignment1/temp
FULL_LOGGING=false
LOGFLAG=false
LOGS=$HOME/assignment1/logs
LOGERR=$LOGS/log.err
LOGTMP=$LOGS/log.tmp
LOGOUT=$LOGS/log.out
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
ACTION=backup
cd "$BASEDIR"
source "$CONFILE"
rm -R $RESTORE_COMP_DIRECTORY
if [[ ! -d "$RESTORE_COMP_DIRECTORY" ]]; then
mkdir -p "$RESTORE_COMP_DIRECTORY"
fi
# if dir is not empty exit
if [[ "$(ls -A $RESTORE_COMP_DIRECTORY)" ]]; then
echo "Dir "$RESTORE_COMP_DIRECTORY" is not empty exiting"
exit
fi
# take filenames into array
cd $BACKUP_FILES_DIRECTORY
RESTORES="${@}"
for f in $RESTORES
do
f=`echo "$f" | sed 's/^[ \t]*//;s/[ \t]*$//'` # trailing whitespaces
if [[ -f ${f}.tar.gz ]]
then
tar -xzvf $BACKUP_FILES_DIRECTORY/$f.tar.gz -C $RESTORE_COMP_DIRECTORY
echo "SUCCESS"
sleep 3s
else
echo -e "File not found for "$f" please make sure is present. ...."
sleep 3s
exit
fi
done
cd $RESTORE_COMP_DIRECTORY
for i in `ls`;do find $IMPORTANT_FILES_DIRECTORY -name $i; done