Hello - I have a small diff script that checks 2 directories. It reports the difference in count such as wc -l, and also names the different files.
How should I get "ERROR: diff found . (host)" - when it actually finds a diff?
This is how I have written:
#!/bin/bash
DIFF=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only | wc -l)
DIFF2=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only)
echo "The file count difference between master folder and CE-B-CM\D folder is:
${DIFF}"
echo "The names of the different files and their paths are:
${DIFF2}."
echo "####################################################"
That is only giving me my own local host name. Not the path to the host where the difference is found and the count...
i use this script, however, I am not able to flag the email subject line to either ERROR or GOOD, have a look:
#!/bin/bash
# Diff script to be used for file comparisions
DIFF=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | wc -l)
if [ $DIFF -ne 0 ]
then
echo "ERROR: Diff found a diff in total count of this many files: ${DIFF}."
forproblemmail=1
else
echo "No Difference"
fi
DIFF2=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only)
if [ $? -eq 0 ]
then
echo "The names of the different files and their paths are:
${DIFF2}."
forproblemmail=1
else
echo "No files are different"
fi
#Email Module
if [ $forproblemmail - eq 1 ] ; then
SUBJECT="ERROR: Problem During Diff"
else
SUBJECT="GOOD: Complete Find Files With Success"
fi
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
Assign a value to the variable forproblemmail in the else part:
if [ $? -eq 0 ]
then
echo "The names of the different files and their paths are:
${DIFF2}."
forproblemmail=1
else
echo "No files are different"
if [ -z $forproblemmail ]; then
forproblemmail=0
fi
fi