Tuesday, February 1, 2011

BASH : File Differences

touch filediff.sh -> monitor direcotry for file changes. First we have to make a snap shot
ls -A > filelist1 ; is like a snapshot. This should be moved in a different location
ls -ltr
mkdir /usr/local/filediff
mv filelist1 /usr/local/filidiff
ls -l /usr/local/filediff
diff -> utilitary to difference 2 files
ls -A > /usr/local/filediff/filelist2
diff filelist1 filelist2
diff filelist1 filelist2 | cut -f 2 -d ' ' -> Results 9d8 filelist1


#!/bin/bash
#filelist1 is created manually by the administrator
MONITORDIR="/root/dirToMonitor"
ls -A $MONITORDIR> filelist2
FILEDIFF=`diff filelist1 filelist2 | cut -f 2 d ' '`
echo $FILEDIFF
#END
mv filediff.sh /usr/local/filediff -> in that folder we have the script and the 2 files that we want cu compare
. filediff.sh -> returns 9d8 filelist1


#!/bin/bash
#filelist1 is created manually by the administrator
MONITORDIR="/root/dirToMonitor"
ls -A $MONITORDIR> filelist2
FILEDIFF=`diff filelist1 filelist2 | cut -f 2 d ' '`
for file in $FILEDIFF
do
if [ -e $file]
then
echo $file
fi
done
#END
. filediff.sh -> returns filelist1


rm -rf filelist*
ls -A ~/temp > filelist1
. filediff.sh -> no differences
touch testingfilediffmonitorscript
. filediff.sh -> no differences. There is one difference
#!/bin/bash
#filelist1 is created manually by the administrator
MONITORDIR="/root/dirToMonitor"
ls -A $MONITORDIR> filelist2
FILEDIFF=`diff filelist1 filelist2 | cut -f 2 d ' '`
for file in $FILEDIFF
do
if [ -e $MONITORDIR/$file]
then
echo $file
fi
done
#END
. filediff.sh ->detects the new file testingfilediffmonitorscript
. filediff.sh > filediff.log.`date +%F`

No comments:

Post a Comment