#!/bin/bash # Clean thumbnails cache # Copyright (c)2007 mwgamera < mwgamera (a) gmail.com > # CONFIGURATION LIFE=1209600 LOG=${HOME}/.thumbnails/clean.log; TIME=`date +%s` # Get URI of thumbnail getthuri() { pngmeta "$f" | awk -F ': ' -- '/Thumb::URI:/{print$2}'; } for f in ${HOME}/.thumbnails/*/*.png; do ATIME=`stat -c%X "$f"` if [ `dc -e "$TIME $ATIME -p"` -gt "$LIFE" ]; then URI=`getthuri` echo "[`date -Imin`] UNUSED $URI" >> $LOG rm "$f" >&2 2>/dev/null else URI=`getthuri` # Get local path if it's local, empty string otherwise LOCAL=`awk -F 'file://' -- '/^file:\/\/\//{print$2}' <<< "$URI"` # If it's local check if base file still exists if [ ! -z "$LOCAL" -a ! -e "$LOCAL" ]; then echo "[`date -Imin`] NONEXISTENT $URI" >> $LOG rm "$f" >&2 2>/dev/null elif [ ! -z `egrep '^(http|ftp)s?://' <<< "$URI"` ]; then # External - check with wget if wget -q --spider "$URI"; then true; else echo "[`date -Imin`] NONEXISTENT $URI" >> $LOG rm "$f" >&2 2>/dev/null fi fi fi done