%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/bin/
Upload File :
Create Path :
Current File : //usr/local/bin/deletewpcache.sh

#!/bin/sh
#
#  clean wordpress cache data

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
set -e

print_usage()
{
    cat <<-__EOT__
	usage: `basename $0` [-h] [-f]
	    -f : (Caution!) delete user wordpress cache data
	    -c : check target user wordpress cache data
	    -h : print help
	__EOT__
    exit 1;
}
# require `-f' option
action=
while getopts fch var; do
    case "$var" in
    f)
        action=delete
        ;;
    c)
        action=check
        ;;
    h|*)
        print_usage
        ;;
    esac
done
test -z "$action" && print_usage

user=$(whoami)
cd /tmp
for wpcachefile in $(find ~/db/pkg/ -type f -name +SAKURA_DELETECACHE 2>/dev/null | grep -E /wordpress-"[0-9.]+","[a-z0-9]+"/\\+SAKURA_DELETECACHE$)
do
    cachepath=$(head -1 $wpcachefile)
    portspath=$(dirname $wpcachefile)
    test -e $portspath/+DEINSTALL || continue
    wppath=$(grep ^INDEXDIR $portspath/+DEINSTALL | cut -d\" -f2)
    deletetarget=${wppath}${cachepath}
    # Check SAKURA_DELETECACHE
    if [ "$cachepath" != "/wp-content/cache" ] ; then
        continue
    fi
    # Check WordPress Directory
    echo "$wppath" | grep -q ^/home/${user}/www || continue
    # Check Target Directory exist
    test -e "$deletetarget" || continue
    # Do delete cache
    echo target: "$deletetarget"
    if [ "$action" = "delete" ] ; then
        find $deletetarget -type f -mtime +3d -print0 | xargs -0 rm -v
    elif [ "$action" = "check" ] ; then
        find $deletetarget -type f -mtime +3d -print
    fi
done

Zerion Mini Shell 1.0