Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mschultheiss83/a0be97b06da47e2ff59e to your computer and use it in GitHub Desktop.
Save mschultheiss83/a0be97b06da47e2ff59e to your computer and use it in GitHub Desktop.
#!/bin/bash
LOG=var/log/del_unused_img.log
function search_db() {
COUNT=$(mysql -uYOURUSER -pYOURPASSWORD YOURDB --execute="SELECT count(*) FROM catalog_product_entity_media_gallery WHERE value = \"$1\"")
echo $(echo ${COUNT} | cut -d" " -f2)
}
echo "Start: "\n >> ${LOG}
echo $(date) >> ${LOG}
for IMG in $(find media/catalog/product/ -name '*.jpg' ! -path '*cache*' ); do
# search in db
if [ $(search_db ${IMG/'media/catalog/product'/}) != 1 ]; then
IMG=${IMG##*/}
for CACHE_IMG in $(find media/catalog/product/ -name "${IMG}"); do
echo "${CACHE_IMG}" >> ${LOG}
rm "${CACHE_IMG}"
done
fi
done
echo "End: "\n >> ${LOG}
echo $(date) >> ${LOG}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment