Created
May 8, 2014 14:52
-
-
Save mschultheiss83/a0be97b06da47e2ff59e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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