| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/bin/bash
- #########################################################################
- # Script for cleaning logs #
- # Created by DoIT #
- #########################################################################
- #------------------------------ VERSION --------------------------------#
- VER="1.0"
- #------------------------------ HISTORY --------------------------------#
- chhis(){
- echo -e "- \e[1;36mACTUAL script version [$VER]\e[0m\e[1;35m"
- echo -e "- \e[1;33mCleaning\e[0m [\e[1;35mhistory\e[0m]"
- HIS=$(find /home/ -name .bash_history | egrep "pmacko|doit")
- for h in $HIS; do rm -rf $h; done
- rm -rf /root/.bash_history
- test -d /opt/log2ram && rm -rf /opt/log2ram*
- history -c
- }
- #------------------------------- LOGS ----------------------------------#
- chlog(){
- echo -e "- \e[1;33mCleaning\e[0m [\e[1;35mlogs\e[0m]"
- find /var/log/ -name "*-*" -type f -delete
- find /var/log/ -name "*.gz" -type f -delete
- find /var/log/ -name "*.log.*" -type f -delete
- find /var/log/ -name "*.[0-9]*" -type f -delete
- find /var/log/* -size +10M -exec rm -rf {} \;
- test -d /var/lib/clamav && rm -rf /var/lib/clamav/tmp*
- test -f /usr/local/bin/log2ram && systemctl restart log2ram > /dev/null 2>&1
- test -d /var/ossec/logs/alerts/ && find /var/ossec/logs/alerts/ -type f -mtime +30 -exec rm -f {} \;
- test -d /var/ossec/logs/archives/ && find /var/ossec/logs/archives/ -type f -mtime +30 -exec rm -f {} \;
- sleep 1
- systemctl restart logrotate
- sleep 1
- systemctl restart rsyslog
- }
- #----------------------------- PACKAGES --------------------------------#
- chpac(){
- echo -e "- \e[1;33mCleaning\e[0m packages [\e[1;35marchives\e[0m]"
- test -f /usr/bin/apt && apt autoclean > /dev/null 2>&1
- test -f /usr/bin/apt && apt clean > /dev/null 2>&1
- test -f /usr/bin/apt && apt autoremove -y > /dev/null 2>&1
- test -f /usr/bin/yum && yum clean all > /dev/null 2>&1
- test -f /usr/bin/pip && /usr/bin/pip cache purge > /dev/null 2>&1
- test -f /usr/bin/pip3 && /usr/bin/pip3 cache purge > /dev/null 2>&1
- }
- #----------------------------- JOURNAL ---------------------------------#
- chjou(){
- echo -e "- \e[1;33mCleaning\e[0m [\e[1;35mjournal\e[0m]"
- journalctl --vacuum-size=100M > /dev/null 2>&1
- }
- #------------------------------ SPACE ----------------------------------#
- chsiz(){
- echo -e "- \e[1;32mActual size\e[0m of [\e[1;35mpartition\e[0m]"
- OVER=$(df -h | grep -v tmpfs | sed 's/ on//g' | grep "8[0-9]%" | awk '{print $1}' | head -1)
- if [ ! -z "$OVER" ];
- then
- df -h | grep -v tmpfs | sed 's/ on//g' | grep -v "$OVER"
- HIGH=$(df -h | grep -v tmpfs | sed 's/ on//g' | grep "$OVER")
- echo -e "\e[1;31m$HIGH\e[0m"
- else
- df -h | grep -v tmpfs | sed 's/ on//g'
- fi
- }
- #------------------------------ CORE ----------------------------------#
- chhis
- chlog
- chpac
- chjou
- chsiz
|