Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SEARCH_PATTERN="$2"
  4. CACHE_DIR="$3"
  5.  
  6.  
  7. if [ -d "${CACHE_DIR}" ]
  8. then
  9.         count=$(find ${CACHE_DIR} | wc -l)
  10.         size=$(du -sh ${CACHE_DIR})
  11.         echo "Total cached files: ${count}, size: ${size}"
  12. else
  13.         echo "CACHE_DIR not defined"
  14.         exit 1
  15. fi
  16.  
  17. case "$1" in
  18.         search)
  19.                 find ${CACHE_DIR} -type f | xargs strings -f 2>/dev/null | egrep -ow "KEY.*${SEARCH_PATTERN}.*"
  20.         ;;
  21.         delete)
  22.                 find ${CACHE_DIR} -type f |
  23.                 xargs strings -f 2>/dev/null |
  24.                 egrep -ow ".*KEY.*${SEARCH_PATTERN}.*" |
  25.                 while read x
  26.                 do
  27.                         x=(${x/:/})
  28.                         [ -f "${x}" ] && rm -v ${x}
  29.                 done
  30.         ;;
  31.  
  32.         search_url_file)
  33.                 find ${CACHE_DIR} -type f | xargs strings -f 2>/dev/null | egrep -ow ".*KEY.*${SEARCH_PATTERN}.*"
  34.         ;;
  35.         list)
  36.                 find ${2} -type f | xargs strings -f 2>/dev/null | egrep -w "KEY.*"
  37.         ;;
  38.         default)
  39.                 exit 1
  40.         ;;
  41. esac
  42.  
  43.  
  44.  
  45. if [ -z "$CACHE_DIR" ]
  46. then
  47.         echo "cache_dir not defined"
  48.         exit 1
  49. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement