A problem encountered earlier is that the log file is too large to occupy the disk space and cause the build project to fail
So I wanted to write a timed task. Delete a log or compress a log file
I've been on the internet for a long time and haven't found the right script.
So I consulted others, wrote a, share to the not found and need such a script novice students
Advantages: Timed compression, save space
Find log files that need to be compressed or deleted on demand
Named rm_log.sh
The shell script is as follows:
#!/bin/bash
Date
CD ${home}
Tomcat_loglist= ' Find. -type d-name "Logs"
Fortomcat_dir in $TOMCAT _loglist;
Todo
CD ${home} && CD ${tomcat_dir}&& CD.
If [-D "bin"] &&[-D "WebApps"]&& [-D "Conf"] && [D "Lib"]; Then
CD ${home} &&cd${tomcat_dir}
file_list=$ (find.-name "catalina.*"-mtime +2|grep-v ". Gz")
For i in ${file_list};
Todo
echo "Iis${tomcat_dir} ${i}"
Gzip ${i}
Done
Fi
Done
Of course you need to give him a permission to execute, or it will show a red error.
The next step is to add the timing.
To open a scheduled task edit using the command crontab-e
There are no scheduled tasks before the first line to start editing, and some words are edited in the following order,
It is recommended to comment on a line on a scheduled task
# Log Compression task
0 5 * * */**/**/**/rm_log.sh>>/**/**/**/rm_log.log
Save exit.
ps:0 5 * * * time, daily five o ' clock execution
/**/**/**/rm_log.sh is the path to your script
>>/**/**/**/rm_log.log Log Redirection
Too good to finally solve a problem ...