After a bit of thinking and searching I came up with the following that seems to work Ok. It is rather specific to the folder structure on my Raspberry Pi and to the files I am trying to download but with these changed should be of more general use.
--- shell script ----
#!/bin/sh
change to the data folder
cd ~/Camera_Data/Download
-N option is supposed to only get new files - only works if file is still in the destination folder at next run of WGET -N
wget -N -a WGETout.log http://oiswww.eumetsat.org/IPPS/html/latestImages/EUMETSAT_MSG_RGBFog_WesternEurope.jpg
set variable to download filename
latestfile=EUMETSAT_MSG_RGBFog_WesternEurope.jpg
get checksum of downloaded (latest) file
file1_sha=$( md5sum $latestfile | awk '{print $1}')
check only files starting with 20 to prevent comparing file EUMETSAT_MSG_RGBFog_WesternEurope.jpg with itself
Also prevents checking image files which begin with 'IMG*.JPG' in the same folder
for filename in 20*.jpg ; do
this variable has to be set in the loop
testfile=$filename
Get checksums of next file
file2_sha=$( md5sum $testfile | awk '{print $1}')
# Compare the checksums
if [ "x$file1_sha" = "x$file2_sha" ]
then
printf "Files %s and %s are the same\n" "$latestfile" "$testfile"
# current file already exists
exit 0
else
printf "Files %s and %s are different\n" "$latestfile" "$testfile"
fi
done
executes if no similar files found
printf "No similar files found copy to new name\n"
cp EUMETSAT_MSG_RGBFog_WesternEurope.jpg "$(date +"%Y%m%d-%H%M.jpg")"
exit 0
-- end of script --
The print statements can be removed - they are only there to show it is working.
If you have lots of files in the destination directory it would be better to sort them by latest modification time in the for loop. There are examples of how to do this on the web using 'ls' piped to 'sort' but they did not work for me.
The rejection of files starting with IMG prevents checking the camera image files that get downloaded to the same folder by a python programme. Since there are normally several hundred it provides a performance gain.
I could not get the code block to work so the comments are in in most cases in large bold rather than having the preceding comment #.