BASH   19

delete tmp files

Guest on 23rd November 2022 03:30:09 PM

  1. #!/bin/bash
  2. BIN_FIND=/usr/bin/find
  3. BIN_XARGS=/usr/bin/xargs
  4. BIN_RM=/bin/rm
  5. BIN_DATE=/bin/date
  6.  
  7. test $# -gt 0 && test $1 = '--script' && BIN_RM='echo rm'
  8.  
  9. PATH_TO_TMP=/var/www/html/cod/tmp
  10.  
  11. DAYS_TO_KEEP=5
  12.  
  13. PATH_TO_SESSIONS=${PATH_TO_TMP}/sessions/
  14. PATH_TO_ADO_CACHE=${PATH_TO_TMP}/coca/
  15. PATH_TO_PROCESS_CACHE=${PATH_TO_TMP}/processes/
  16. PATH_TO_UPLOADS=${PATH_TO_TMP}/uploads/
  17.  
  18. set -x
  19.  
  20. ${BIN_FIND} ${PATH_TO_SESSIONS} \
  21.     -name .svn -prune -o \
  22.     -type f -mtime +${DAYS_TO_KEEP} -print \
  23.     | ${BIN_XARGS} --no-run-if-empty -n1 ${BIN_RM} -v
  24.  
  25. ${BIN_FIND} ${PATH_TO_ADO_CACHE} \
  26.     -name .svn -prune -o \
  27.     -type f -mtime +${DAYS_TO_KEEP} -print \
  28.     | ${BIN_XARGS} --no-run-if-empty -n1 ${BIN_RM} -v
  29.  
  30. ${BIN_FIND} ${PATH_TO_PROCESS_CACHE} \
  31.     -mindepth 1 -maxdepth 1 \
  32.     -name .svn -prune -o \
  33.     -type d -mtime +${DAYS_TO_KEEP} -print \
  34.     | ${BIN_XARGS} --no-run-if-empty -n1 ${BIN_RM} -v -r
  35.  
  36. ${BIN_FIND} ${PATH_TO_TMP} \
  37.     -maxdepth 1 \
  38.     -name .svn -prune -o \
  39.     -name arch_\*.zip -mtime +${DAYS_TO_KEEP} -print -o \
  40.     -name arch_\*.zip.\* -mtime +${DAYS_TO_KEEP} -print \
  41.     | ${BIN_XARGS} --no-run-if-empty -n1 ${BIN_RM} -v
  42.  
  43. echo Process completed at `${BIN_DATE} --rfc-3339=seconds`
  44.  
  45. exit 0

Raw Paste


Login or Register to edit or fork this paste. It's free.