Advertisement
emilwojcik93

Untitled

Aug 26th, 2021
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Create log dir/file
  4. log_dir="/var/log/cleanup_script"
  5. log_file="$log_dir/removed_$(date +"%m-%d-%y").log"
  6. if [[ ! -e $log_dir ]]; then
  7.     mkdir -p $log_dir
  8. fi
  9. if [[ ! -e $log_file ]]; then
  10.     touch $log_file
  11. fi
  12.  
  13. # Logging files to delete
  14. find /tmp -iregex '.*\.\(jpg\|gif\|png\|jpeg\|pdf\|doc\|docx\|odt\|log\|xls\|XLS\)$' -type f -delete -exec echo $file >> $log_file {} \;
  15. find /tmp -iregex '.*\.\(sql\|tar\|\|gz\|tar.gz\|xls.gz\)$' -size +200M -type f -delete -exec echo $file >> $log_file {} \;
  16. find /tmp -iregex '.*.xls.gz$' -type f -delete -exec echo $file >> $log_file {} \;
  17. find /var/log -type f -mtime +2 -delete -exec echo $file >> $log_file {} \;
  18. find /home -name cache -type d -prune -exec echo $file >> $log_file {} \;
  19. find /home -name .cache -type d -prune -exec echo $file >> $log_file {} \;
  20. find /home -name .npm -type d -prune -exec echo $file >> $log_file {} \;
  21. find /home -name .yarn-cache -type d -prune -exec echo $file >> $log_file {} \;
  22. find $log_file -size 0 -delete
  23.  
  24. if [[ -e $log_file ]]; then
  25.     rm -f ${HOME}/.duc.db /srv/duc/.duc.db && \
  26.     duc index --exclude=/{proc,sys,dev,var/adarhost,srv/files/upload} / && \
  27.     cp ${HOME}/.duc.db /srv/duc/.duc.db && \
  28.     chown www-data:www-data -R /srv/duc/.duc.db && \
  29.     systemctl reload apache2
  30.     systemctl restart mysql
  31. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement