Tuesday, June 24, 2014

Scripts Check 2 directories

#!/bin/bash
# This script is going to verify make sure all users are backup.

# Home user : /home/[0-9] and /home/[a-z]
# Home backup user: /homebackup/[0-9] and /homebackup/[a-z]

for users in {0..9} {a..z}; do
diff /home/$users/ /homebackup/$users/ | grep /home/$users/ | awk '{print $4}' >> /opt/scripts/differences.txt
done
sed -i -e "/and/d" /opt/scripts/differences.txt

# Check file content
FILE=/opt/scripts/differences.txt
        if [[ -s $FILE ]] ; then
                echo "Has some difference."
                echo "Email Users not backup are:" >> /opt/scripts/mail.tmp
                echo "" >> /opt/scripts/mail.tmp
                        cat /opt/scripts/differences.txt >> /opt/scripts/mail.tmp
                echo "" >> /opt/scripts/mail.tmp
                echo "Please check MX01." >> /opt/scripts/mail.tmp
        mail -s "Mail User Not Backup" ken.vannakk@gmail.com < /opt/scripts/mail.tmp
        # Remove file
        rm /opt/scripts/differences.txt
        rm /opt/scripts/mail.tmp
        else
                echo "No difference."
        # Remove file
        rm /opt/scripts/differences.txt
        fi
# End
==================================================
#!/bin/bash

# This script is going to verify make sure all users are backup.
HOMEUSER=/home/vmail
BACKUPUSER=/homebackup/vmail

# Check the the difference between HOMEUSER and BACKUPUSER
diff $HOMEUSER $BACKUPUSER | grep $HOMEUSER | awk '{print $4}' > /opt/scripts/differences.txt
sed -i -e "/and/d" /opt/scripts/differences.txt

# Check file content
FILE=/opt/scripts/differences.txt
        if [[ -s $FILE ]] ; then
                echo "Has some difference."
                echo "Email Users not backup are:" >> /opt/scripts/vmail.tmp
                echo "" >> /opt/scripts/vmail.tmp
                        cat /opt/scripts/differences.txt >> /opt/scripts/vmail.tmp
                echo "" >> /opt/scripts/vmail.tmp
                echo "Please check MX01." >> /opt/scripts/vmail.tmp
        mail -s "Mail User Not Backup" ken.vannakk@gmail.com < /opt/scripts/vmail.tmp
        # Remove file
        rm /opt/scripts/differences.txt
        rm /opt/scripts/vmail.tmp
        else
                echo "No difference."
        # Remove file
        rm /opt/scripts/differences.txt
        fi
# End

No comments:

Post a Comment