How to use wget with authentication:
syntax:
wget --user=username --ask-password URL
example:
wget --user=lui --ask-password http://asteriskopensourcev2.blogspot.com/sample.zip
Password for user `lui': *********
Done! You will now be able to download.
Tuesday, February 25, 2014
Tuesday, February 11, 2014
Magento delete unused image script
Magento delete unused image script
http://pastebin.com/ysvz6GX2
#!/bin/bash
#modified by John Louis C. Garcia on Feb. 12, 2014
#original source by Pieter at http://www.rapidcommerce.eu/blog/2012/08/remove-unused-magento-product-images/#comment-14649
#works with remote database hostname
#works also if you have cache(memcached/apc) enabled on local.xml
#instruction: change the MAGENTO_PATH.
MAGENTO_PATH="/var/www/magento"
LOG=${MAGENTO_PATH}/var/log/imagecleanup.log
DB_USER=$(sed -n 's|<username><\!\[CDATA\[\(.*\)\]\]></username>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PASS=$(sed -n 's|<password><\!\[CDATA\[\(.*\)\]\]></password>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_NAME=$(sed -n 's|<dbname><\!\[CDATA\[\(.*\)\]\]></dbname>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PREFIX=$(sed -n 's|<table_prefix><\!\[CDATA\[\(.*\)\]\]></table_prefix>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_REMOTEHOST=$(sed -n 's|<host><\!\[CDATA\[\(.*\)\]\]></host>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ' | awk 'END{print}')
function search_db() {
COUNT=$(mysql -u ${DB_USER} -p${DB_PASS} -h ${DB_REMOTEHOST} ${DB_NAME} --execute="SELECT count(*) FROM ${DB_PREFIX}catalog_product_entity_media_gallery WHERE value = \"$1\"")
echo $(echo ${COUNT} | cut -d" " -f2)
}
echo "Starting image cleanup " $(date) | tee -a ${LOG}
IMG_PATH=${MAGENTO_PATH}/media/catalog/product/
for IMG in $(find ${IMG_PATH} -name '*.jpg' ! -path '*cache*' ! -name 'google*'); do
REL_IMG=/${IMG:${#IMG_PATH}}
if [ $(search_db ${REL_IMG/'${MAGENTO_PATH}/media/catalog/product'/}) != 1 ]; then
IMG=${IMG##*/}
for CACHE_IMG in $(find ${MAGENTO_PATH}/media/catalog/product/ -name "${IMG}"); do
echo "Found unused image ${CACHE_IMG}"
if [ "$1" ] && [ $1 == 'cleanup' ]; then
echo "Removing unused image ${CACHE_IMG}" | tee -a ${LOG}
rm "${CACHE_IMG}"
fi
done
else
echo "Not touching " ${IMG}
fi
done
echo "Finished image cleanup " $(date) | tee -a ${LOG}
exit 0;
http://pastebin.com/ysvz6GX2
#!/bin/bash
#modified by John Louis C. Garcia on Feb. 12, 2014
#original source by Pieter at http://www.rapidcommerce.eu/blog/2012/08/remove-unused-magento-product-images/#comment-14649
#works with remote database hostname
#works also if you have cache(memcached/apc) enabled on local.xml
#instruction: change the MAGENTO_PATH.
MAGENTO_PATH="/var/www/magento"
LOG=${MAGENTO_PATH}/var/log/imagecleanup.log
DB_USER=$(sed -n 's|<username><\!\[CDATA\[\(.*\)\]\]></username>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PASS=$(sed -n 's|<password><\!\[CDATA\[\(.*\)\]\]></password>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_NAME=$(sed -n 's|<dbname><\!\[CDATA\[\(.*\)\]\]></dbname>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PREFIX=$(sed -n 's|<table_prefix><\!\[CDATA\[\(.*\)\]\]></table_prefix>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_REMOTEHOST=$(sed -n 's|<host><\!\[CDATA\[\(.*\)\]\]></host>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ' | awk 'END{print}')
function search_db() {
COUNT=$(mysql -u ${DB_USER} -p${DB_PASS} -h ${DB_REMOTEHOST} ${DB_NAME} --execute="SELECT count(*) FROM ${DB_PREFIX}catalog_product_entity_media_gallery WHERE value = \"$1\"")
echo $(echo ${COUNT} | cut -d" " -f2)
}
echo "Starting image cleanup " $(date) | tee -a ${LOG}
IMG_PATH=${MAGENTO_PATH}/media/catalog/product/
for IMG in $(find ${IMG_PATH} -name '*.jpg' ! -path '*cache*' ! -name 'google*'); do
REL_IMG=/${IMG:${#IMG_PATH}}
if [ $(search_db ${REL_IMG/'${MAGENTO_PATH}/media/catalog/product'/}) != 1 ]; then
IMG=${IMG##*/}
for CACHE_IMG in $(find ${MAGENTO_PATH}/media/catalog/product/ -name "${IMG}"); do
echo "Found unused image ${CACHE_IMG}"
if [ "$1" ] && [ $1 == 'cleanup' ]; then
echo "Removing unused image ${CACHE_IMG}" | tee -a ${LOG}
rm "${CACHE_IMG}"
fi
done
else
echo "Not touching " ${IMG}
fi
done
echo "Finished image cleanup " $(date) | tee -a ${LOG}
exit 0;
Subscribe to:
Posts (Atom)