开发者

Script for log file handling

开发者 https://www.devze.com 2023-03-02 01:22 出处:网络
I want to write a script that will check my own log files stored in /var/log/[dir]/[name].log before start logging in these files that whether date of last log message is older than date of current me

I want to write a script that will check my own log files stored in /var/log/[dir]/[name].log before start logging in these files that whether date of last log message is older than date of current message. If it happens then I have to do some operations on these log files and then flush them and start logging again with new date. My daemon process starts at startup of Ubuntu Linux 10.10 in run level 2 3 4 5. So where I have to store this script so that it can check log files from startup and in the middle of running system开发者_运维技巧. And would I have to check it before writing each log message. because this is inefficient method for checking every log message so any suggestion will be appreciated.


You can use the Linux utility logrotate to achieve what you are trying to do. You can simple configuration like

   <Your log file> {
       size=<>
       prerotate
                                 <Your script>
       endscript
       postrotate
                                 <Your script>
       endscript
   }

this for your purpose. Have a look at logrotate man page for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消