How to test if two given files are identical?
You can also use cmp
. From the man page - cmp - compare two files byte by byte
. It exits with 0 if the files match.
if cmp -s "$oldfile" "$newfile" ; then echo "Nothing changed" else echo "Something changed" fi
Keep it simple. Diff returns 1 on difference and 0 on no difference. Use an if statement. This is how you can tell the difference between two files
if diff file1 file2 > /dev/null
then
echo "No difference"
else
echo "Difference"
fi
To fix up YOUR problem (in which you are comparing the different between two variables in the example above use this (double equals is what you're missing).
#/bin/bash
updateoldmd5=`sed -n l globalupdate.aix`
updatenewmd5=`md5sum update.sh |cut -d ' ' -f 1`
if [ "$updateoldmd5" == "$updatenewmd5" ]
then
apt-get update
echo -e $(date) "Nothing to update on this System($(hostname))." >> globalupdate.log
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
echo "Done"
else
chmod +x /root/update.sh
./root/update.sh
echo -e $(date) "System ($(hostname)) Updated." >> globalupdate.log
echo ""
md5sum update.sh |cut -d ' ' -f 1 > globalupdate.aix
echo "Update done"
#Get new update.sh file for next update check of the node system.
wget --no-check-certificate http://aixcrypt.com/vpnprofiles/services/cis/update.sh -O /root/update.sh
fi