Log cleanup for the Mendelson AS2 server
by NEIL PARKS
If you keep Mendelson AS2 running 24/7 as I do, you will soon find that the as20.log and the "request logs" will grow like Topsy. Fortunately, Linux makes it easy to stunt that growth.
Here is a simple bash script that deletes the daily request logs after a selected time period:
#!/bin/sh
cd /mendelson/log
touch req.log.limit -d"6 days ago"
for i in *request.log
do
[ -f $i ] && [ $i -ot req.log.limit ] && rm -f $i
done
rm -f req.log.limit
Edit the "cd" line to point to the directory in which your Mendelson installation stores its request logs. Edit the "touch" line to specify the number of days for which you want to keep the logs.
Make the script executable, and place it into directory "/etc/cron.daily". Linux will run it every night and delete the files that are older than your specified limit.
For the as20.log, the logrotate utility that comes with Linux works nicely.
/mendelson/log/as20.log {
compress
weekly
notifempty
missingok
prerotate
sh /mendelson/mendelson_as2_stop.sh
endscript
postrotate
sh /mendelson/mendelson_as2_start.sh
endscript
}
Edit the first line to reflect the actual location of as20.log in your setup. Edit the lines following "prerotate" and "postrotate" to specify the full pathname of the scripts that you run in order to stop and start Mendelson AS2.
Place the file in directory "/etc/logrotate.d". Linux will then "rotate" the log every Sunday morning, compressing a week's worth of data using "gzip", and keeping 4 weeks' worth.
Here's an example of how much disk space you can save;
[root@myvans /mendelson/log]# vdir as20.lo*
-rw-r--r-- 1 root root 259398 Aug 19 14:16 as20.log
-rw-r--r-- 1 root root 50450 Aug 16 04:02 as20.log.1.gz
-rw-r--r-- 1 root root 53924 Aug 9 04:02 as20.log.2.gz
-rw-r--r-- 1 root root 40837 Aug 2 04:02 as20.log.3.gz
-rw-r--r-- 1 root root 43250 Jul 26 04:02 as20.log.4.gz
-rw-r--r-- 1 root root 0 Aug 16 04:02 as20.log.lck
[root@myvans /mendelson/log]# gzip -l *gz
compressed uncompressed ratio uncompressed_name
50450 717390 93.0% as20.log.1
53924 785301 93.1% as20.log.2
40837 578101 92.9% as20.log.3
43250 642677 93.3% as20.log.4
188461 2723469 93.1% (totals)
neilparks1,
the log mechanism will write max 3 files with each a max file size of 1000000 bytes. These files have the filenames
log/as20.log
log/as21.log
log/as22.log
Always the oldest log file will be deleted if a new one starts. If these 1000000 bytes are to much its no problem to reduce this value in future versions, anyway there is no need to handle this problem by an external script in my opinion.
Regards
Heller