I have a folder structure in /var/log like this:
.
├── customers
│ ├── core00001
│ │ ├── 2016.07.21
│ │ │ ├── apache.log
│ │ │ └── error.log
│ │ └── 2016.07.22
│ │ ├── apache.log
│ │ └── error.log
│ ├── core00002
│ │ ├── 2016.07.21
│ │ │ ├── apache.log
│ │ │ └── error.log
│ │ └── 2016.07.22
│ │ ├── apache.log
│ │ └── error.log
│ ├── dashboard001
│ │ ├── 2016.07.21
│ │ │ ├── dash.log
│ │ │ └── error.log
│ │ └── 2016.07.22
│ │ ├── dash.log
│ │ └── error.log
│ └── dashboard002
│ ├── 2016.07.21
│ │ ├── dash.log
│ │ └── error.log
│ └── 2016.07.22
│ ├── dash.log
│ └── error.log
└── servers
├── server01
│ ├── 2016.07.21
│ │ ├── access.log
│ │ └── system.log
│ └── 2016.07.22
│ ├── access.log
│ └── system.log
└── server02
├── 2016.07.21
│ ├── access.log
│ └── system.log
└── 2016.07.22
├── access.log
└── system.log
With these folders I need to do some sort of log rotation. It's not real log rotation, but I need to zip and delete files after a certain amount of days. I thought of making a config file in which I can put the amount of days after a file needs to be zipped and the amount of days after a file and empty folder needs to be deleted.
The cores and servers can increase and log file names can be added with each server. For this reason I thought of using a config file with the bash script, so I can add names in here.
My first idea of the config file is like this:
Zip;Delete;Main;Sub;App
7;365;/customers;core*;/apache.log
7;365;/customers;core*;/error.log
7;180;/customers;dash*;/dash.log
7;180;/customers;dash*;/error.log
28;365;/servers;server*;/access.log
14;365;/servers;server*;/error.log
My problem lies in that I don't know how to accomplish this without any help.
I already tried to create a loop where the config file will be read, but then only 1 line will be read and the script stops.
#!/bin/bash
configfile="/etc/customlogrotate/logrotation.conf"
logbasefolder="/var/log"
echo " " > log.txt
echo " " >> log.txt
echo "Starting logrotation script" >> log.txt
while IFS=';' read -r daysafterzip daystosave sectionfolder logfilename
do
echo "$daysafterzip $daystosave $logbasefolder$sectionfolder$logfilename" >> log.txt
cd $logbasefolder
done < "$configfile"
Recent Questions...
ما را در سایت Recent Questions دنبال میکنید
برچسب:
نویسنده: استخدام کار
بازدید: 251
تاريخ: سه
شنبه
5 مرداد
1395 ساعت: 17:09