I am trying to use md5sum to compare two files in a bash script.
The goal is to use the .md5 one file to check the md5sum another file. My Google searches for how to do this do not show me how I do this. Disabling email works the way you expected. Now I'm trying to get him to turn off email when it fails, not in success.
And perhaps list the result of what was obtained from the .md5 file and the actual md5sum damaged file. Iβll find out in the end, but itβs somewhat confusing, since I tried to find out where I am not here.
Shellcheck indicates that the code looks good, but I am not getting the results that I expect to get.
A few StackOverflow links that I checked to see if something could work:
One
Two
Here is the contents of my bash script in its original form:
#!/bin/bash cd /home/example/public_html/exampledomain.com/billing/system/ || exit rm -rf GeoLiteCity.dat curl -L https://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | gunzip > GeoLiteCity.dat curl -L https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz | gunzip > GeoLite2-City.dat curl -L https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.md5 md5sum GeoLite2-City.dat > md5sum.txt file1="md5sum.txt" file2="GeoLite2-City.md5" if [ "`cat $file1`" != "`cat $file2`" ]; then mail -s "Results of GeoLite Updates" email@address.com <<< "md5sum for GeoLite2-City failed. Please check the md5sum. File may possibly be corrupted." else exit fi
Edit:
Updated code to the following:
#!/bin/bash cd /home/example/web/exampledomain/public_html/billing/system/ || exit rm -rf GeoLite* rm -rf md5sum.txt curl -L https://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | gunzip > GeoLiteCity.dat curl -L https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz | gunzip > GeoLite2-City.dat wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.md5 md5sum GeoLite2-City.dat > md5sum.txt file1="md5sum.txt" file2="GeoLite2-City.md5" if ! cmp "$file1" "$file2"; then echo "They don't match."; fi
Still working on it. Closer to getting it to work!
The results of the above:
root@example
Edit2: Code now looks like this. Also note that I delete GeoLiteCity2 and GeoLite so that we start a new database load every time MaxMind updates its database:
#!/bin/bash
source share