Guest User

Untitled

a guest
Dec 8th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # jfindfiles -- Find used and unused content files in your Joomla website
  4. #
  5. # This scripts supports Joomla versions 2.5 - 3.x
  6. #
  7. # Copyright 2014 Rene Kreijveld - email@renekreijveld.nl
  8. #
  9. # This program is free software; you may redistribute it and/or modify it.
  10. #
  11. # Warning! This script needs the file jfunctions. This has to be installed in the same directory as this script.
  12. #
  13.  
  14. # general variables
  15. mypath=$(cd $(dirname ${0}); pwd -P)
  16. myname=$(basename ${0})
  17.  
  18. # include general functions
  19. . ${mypath}/jfunctions
  20.  
  21. # version
  22. version=2.2
  23.  
  24. # Setup Vvariables
  25. start=./images
  26. curdir=`pwd`
  27.  
  28. echo "Creating database dump..."
  29.  
  30. # Dump the database to a .sql file
  31. if mysqldump --skip-opt --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset --host=${host} --user=${dbuser} --password=${password} ${database} > ${database}.sql
  32. then
  33. echo "Database dump ${database}.sql created."
  34. else
  35. echo "Error creating database dump."
  36. exit 1
  37. fi
  38.  
  39. dbdump=${curdir}/${database}.sql
  40. usedfile=${curdir}/${sitename}-used.txt
  41. notusedfile=${curdir}/${sitename}-notused.txt
  42. echo "The following files were mentioned in your Joomla database:" > ${usedfile}
  43. echo "The following files were NOT mentioned in your Joomla database:" > ${notusedfile}
  44. echo "Checking for used and unused files..."
  45.  
  46. # Move into the images/stories directory
  47. cd ${start}
  48. # Find all files and check if they are mentioned in the database dump
  49. for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'`
  50. do
  51. file2=`echo $file | sed 's/#}/ /g'`
  52. file3=`echo $file | sed 's/#}/%20/g'`
  53. if grep -c "$file2" ${dbdump} > 0; then
  54. echo $file2 >> ${usedfile}
  55. elif grep -c "$file3" ${dbdump} > 0; then
  56. echo $file3 >> ${usedfile}
  57. else
  58. echo $file3 >> ${notusedfile}
  59. fi
  60. done
  61.  
  62. # Move back to the root of the website
  63. cd ${curdir}
  64.  
  65. # Cleanup database dump
  66. rm ${dbdump}
  67.  
  68. # Report findings
  69. echo "Files checking done."
  70. echo "Check the following text-files for results:"
  71. echo "${usedfile}"
  72. echo "${notusedfile}"
Add Comment
Please, Sign In to add comment