Auto Delete Log - n05urpr1532-MHA-Team/PTS-Team GitHub Wiki
This is not needed anymore , it will automatic deployed ;-)
Table of Contents
1. Intro
Today I will tell you how to use this script to blur its tracks and login traces. In advance: any change you make or similar is on a responsibility
The files of logs are in /var/log
tree -u -L 2 /var/log/
tree -u -L 2 /var/log/
/var/log/
├── [root] alternatives.log <---- that`s log file !!
├── [root] apt <---- never delete the folder !!
|
├── [root] fail2ban.log <---- never delete this file !!
├── [root] fu.log <---- that`s log file !!
├── [root] installer <---- never delete the folder !!
|
├── [root] sysstat <---- never delete the folder !!
|
└── [root] unattended-uPTSrades <---- never delete the folder !!
2. The Script
- su > to root access !
- cd /root/
- nano killop.sh
- add the lines below ( killop.sh )
- CTRG + X
- choma a+x /root/killop.sh
- past this lines
sudo sed -i '$a\*/5 * * * * bash -x /root/killop.sh >/dev/null 2>&1 >/dev/null 2>&1\' /var/spool/cron/crontabs/root
sudo sed -i '$a\@reboot bash /root/killop.sh >/dev/null 2>&1\' /var/spool/cron/crontabs/root
and finish !
[Script]
#!/bin/bash
# settings
# file names to filter
UNWANTED_FILES=(
'vsftpd.log'
'syslog'
'daemon.log'
'kern.log'
'messages'
'syslog'
'lastlog'
'php5-fpm-log'
'user.log'
'faillog'
'fontconfig.log'
'debug'
'dpkg.log'
)
# advanced settings
FIND=$(which find)
FIND_BASE_CONDITION='-type f'
FIND_ADD_NAME='-o -name'
FIND_ACTION=' -delete'
#Folder Setting
#Folder Setting
TARGET_FOLDER=$1'/var/log/'
TARGET_FOLDER=$1'/var/log/'
if [ ! -d "${TARGET_FOLDER}" ]; then
echo 'Target directory does not exist.'
exit 1
fi
condition="-name '${UNWANTED_FILES[0]}'"
for ((i = 1; i < ${#UNWANTED_FILES[@]}; i++))
do
condition="${condition} ${FIND_ADD_NAME} '${UNWANTED_FILES[i]}'"
done
command="${FIND} '${TARGET_FOLDER}' ${FIND_BASE_CONDITION} \( ${condition} \) ${FIND_ACTION}"
echo "Executing ${command}"
eval ${command}
exit 0
You can add more variables if you add the name of the log file in -->
UNWANTED_FILES=( 'name of file'