I have this little script i wrote to use the diff command to check two directories, if they are exactly the same the first one is deleted.
here is the script as it sits now.
Code:
#! /bin/bash
diff -qr "$1" "$2" > /dev/null
v1=$?
if [ $v1 = 0 ]
then
rm -Rf "$1"
echo "$1 was removed"
else
SUBJECT="Did not Remove a folder"
TO="myemail@address.com"
MESSAGE="/msg/checkdiffmsg.txt"
echo "Not Right. Did Not Remove The Directory" >> $MESSAGE
echo "$1" >> $MESSAGE
/usr/bin/mail -s "$SUBJECT" "$TO" < "$MESSAGE"
rm $MESSAGE
fi
the script is called using this command line
checkdiff.sh dir1 dir2
the script is working well with one problem.
when the rm command is issued, sometimes the files are locked and the directory cannot be removed.
is there a way for me to check for this? or at least to shoot myself an email and tell me that it did not happen?
Thanks in advance.
-C