X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fexicyclog.src;h=b4aa018a06e1a4084043f6784e9b6244a968fb22;hb=c8ea159758f4f58b63cebc77067f53264a10f0cf;hp=4762f21f796e43905472f53c973be91e611ac231;hpb=059ec3d9952740285fb1ebf47961b8aca2eb1b4a;p=exim.git diff --git a/src/src/exicyclog.src b/src/src/exicyclog.src index 4762f21f7..b4aa018a0 100644 --- a/src/src/exicyclog.src +++ b/src/src/exicyclog.src @@ -1,5 +1,5 @@ #! /bin/sh -# $Cambridge: exim/src/src/exicyclog.src,v 1.1 2004/10/07 10:39:01 ph10 Exp $ +# $Cambridge: exim/src/src/exicyclog.src,v 1.4 2005/06/16 15:48:58 ph10 Exp $ # Copyright (c) 2004 University of Cambridge. # See the file NOTICE for conditions of use and distribution. @@ -24,8 +24,10 @@ # This is a shell script for cycling exim main and reject log files. Each time # it is run, the files get "shuffled down" by one, the current one (e.g. # mainlog) becoming mainlog.01, the previous mainlog.01 becoming mainlog.02, -# and so on, up to the limit configured here. The same happens to the reject -# logs. All those with numbers greater than 1 are compressed. +# and so on, up to the limit configured here. When the number to keep is +# greater than 99 (not common, but some people do it), three digits are used +# (e.g. mainlog.001). The same shuffling happens to the reject logs. All +# renamed files with numbers greater than 1 are compressed. # This script should be called regularly (e.g. daily) by a root crontab # entry of the form @@ -137,10 +139,19 @@ fi log_file_path=`echo "$log_file_path" | \ sed 's/^ *:\{0,1\} *syslog *:\{0,1\} *//;s/: *syslog *:/:/;s/: *syslog *$//'` -# If log_file_path is empty, then the logs we are interested in are called -# "mainlog" and "rejectlog" in the directory called "log" in the spool -# directory. Otherwise we fish out the directory from the given path, and -# also the names of the logs. +# If log_file_path is empty, try and get the compiled in default by using +# /dev/null as the configuration file. + +if [ "$log_file_path" = "" ]; then + log_file_path=`$exim_path -C /dev/null -bP log_file_path | sed 's/.*=[ ]*//'` + log_file_path=`echo "$log_file_path" | \ + sed 's/^ *:\{0,1\} *syslog *:\{0,1\} *//;s/: *syslog *:/:/;s/: *syslog *$//'` +fi + +# If log_file_path is still empty, the logs we are interested in are probably +# called "mainlog" and "rejectlog" in the directory called "log" in the spool +# directory. Otherwise we fish out the directory from the given path, and also +# the names of the logs. if [ "$log_file_path" = "" ]; then logdir=$spool_directory/log @@ -202,11 +213,18 @@ if [ -f $rejectlog.$keept.$suffix ]; then $rm $rejectlog.$keept.$suffix; fi; # When the number is less than 10, insert a leading zero. count=$keep -if [ $count -lt 10 ]; then countt=0$count; else countt=$count; fi; +if [ $count -lt 10 ]; then countt=0$count; else countt=$count; fi while [ $count -gt 1 ]; do old=`expr $count - 1` - if [ $old -lt 10 ]; then oldt=0$old; else oldt=$old; fi; + if [ $keep -gt 99 ]; then + if [ $old -lt 10 ]; then oldt=00$old + elif [ $old -lt 100 ]; then oldt=0$old + else oldt=$old + fi + else + if [ $old -lt 10 ]; then oldt=0$old; else oldt=$old; fi; + fi if [ -f $mainlog.$oldt ]; then $mv $mainlog.$oldt $mainlog.$countt elif [ -f $mainlog.$oldt.$suffix ]; then @@ -221,25 +239,34 @@ while [ $count -gt 1 ]; do countt=$oldt done -# Now rename the current files as 01 +# Now rename the current files as 01 or 001 if keeping more than 99 + +if [ $keep -gt 99 ]; then first=001; else first=01; fi if [ -f $mainlog ]; then - $mv $mainlog $mainlog.01 - $chown $user:$group $mainlog.01 + $mv $mainlog $mainlog.$first + $chown $user:$group $mainlog.$first fi if [ -f $rejectlog ]; then - $mv $rejectlog $rejectlog.01 - $chown $user:$group $rejectlog.01 + $mv $rejectlog $rejectlog.$first + $chown $user:$group $rejectlog.$first fi -# Now scan the 02 and later files, compressing where necessary, and +# Now scan the (0)02 and later files, compressing where necessary, and # ensuring that their owners and groups are correct. count=2; while [ $count -le $keep ]; do - if [ $count -lt 10 ]; then countt=0$count; else countt=$count; fi + if [ $keep -gt 99 ]; then + if [ $count -lt 10 ]; then countt=00$count + elif [ $count -lt 100 ]; then countt=0$count + else countt=$count + fi + else + if [ $count -lt 10 ]; then countt=0$count; else countt=$count; fi + fi if [ -f $mainlog.$countt ]; then $compress $mainlog.$countt; fi if [ -f $mainlog.$countt.$suffix ]; then $chown $user:$group $mainlog.$countt.$suffix