Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Create log dir/file
- log_dir="/var/log/cleanup_script"
- log_file="$log_dir/removed_$(date +"%m-%d-%y").log"
- if [[ ! -e $log_dir ]]; then
- mkdir -p $log_dir
- fi
- if [[ ! -e $log_file ]]; then
- touch $log_file
- fi
- # Logging files to delete
- find /tmp -iregex '.*\.\(jpg\|gif\|png\|jpeg\|pdf\|doc\|docx\|odt\|log\|xls\|XLS\)$' -type f -delete -exec echo $file >> $log_file {} \;
- find /tmp -iregex '.*\.\(sql\|tar\|\|gz\|tar.gz\|xls.gz\)$' -size +200M -type f -delete -exec echo $file >> $log_file {} \;
- find /tmp -iregex '.*.xls.gz$' -type f -delete -exec echo $file >> $log_file {} \;
- find /var/log -type f -mtime +2 -delete -exec echo $file >> $log_file {} \;
- find /home -name cache -type d -prune -exec echo $file >> $log_file {} \;
- find /home -name .cache -type d -prune -exec echo $file >> $log_file {} \;
- find /home -name .npm -type d -prune -exec echo $file >> $log_file {} \;
- find /home -name .yarn-cache -type d -prune -exec echo $file >> $log_file {} \;
- find $log_file -size 0 -delete
- if [[ -e $log_file ]]; then
- rm -f ${HOME}/.duc.db /srv/duc/.duc.db && \
- duc index --exclude=/{proc,sys,dev,var/adarhost,srv/files/upload} / && \
- cp ${HOME}/.duc.db /srv/duc/.duc.db && \
- chown www-data:www-data -R /srv/duc/.duc.db && \
- systemctl reload apache2
- systemctl restart mysql
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement