#! /bin/sh # Copyright (c) University of Cambridge, 1995 - 2015 # See the file NOTICE for conditions of use and distribution. # This script takes the following command line arguments: # -l dir Log file directory # -k days Number of days to keep the log files # Except when they appear in comments, the following placeholders in this # source are replaced when it is turned into a runnable script: # # CONFIGURE_FILE_USE_NODE # CONFIGURE_FILE_USE_EUID # CONFIGURE_FILE # BIN_DIRECTORY # EXICYCLOG_MAX # COMPRESS_COMMAND # COMPRESS_SUFFIX # CHOWN_COMMAND # CHGRP_COMMAND # CHMOD_COMMAND # TOUCH_COMMAND # MV_COMMAND # RM_COMMAND # PROCESSED_FLAG # 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. 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 # 1 0 * * * /opt/exim/bin/exicyclog # The following lines are generated from Exim's configuration file when # this source is built into a script, but you can subsequently edit them # without rebuilding things, as long are you are careful not to overwrite # the script in the next Exim rebuild/install. "Keep" is the number of old log # files that are required to be kept. Its value can be overridden by the -k # command line option. "Compress" and "suffix" define your chosen compression # method. The others are provided because the location of certain commands # varies from OS to OS. Sigh. keep=EXICYCLOG_MAX compress=COMPRESS_COMMAND suffix=COMPRESS_SUFFIX chgrp=CHGRP_COMMAND chmod=CHMOD_COMMAND chown=CHOWN_COMMAND mv=MV_COMMAND rm=RM_COMMAND touch=TOUCH_COMMAND # End of editable lines ######################################################################### # Sort out command line options. while [ $# -gt 0 ] ; do case "$1" in -l) log_file_path=$2 shift ;; -k) keep=$2 shift ;; --version) echo "`basename $0`: $0" echo "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION" exit 0 ;; *) echo "** exicyclog: unknown option $1" exit 1 ;; esac shift done # Some operating systems have different versions in which the commands live # in different places. We have a fudge that will search the usual suspects if # requested. for cmd in chgrp chmod chown mv rm touch; do eval "oldcmd=\$$cmd" if [ "$oldcmd" != "look_for_it" ] ; then continue ; fi newcmd=$cmd for dir in /bin /usr/bin /usr/sbin /usr/etc ; do if [ -f $dir/$cmd ] ; then newcmd=$dir/$cmd break fi done eval $cmd=$newcmd done # See if this installation is using the esoteric "USE_EUID" feature of Exim, # in which it uses the effective user id as a suffix for the configuration file # name. In order for this to work, exicyclog must be run under the appropriate # euid. if [ "CONFIGURE_FILE_USE_EUID" = "yes" ]; then euid=.`id -u` fi # See if this installation is using the esoteric "USE_NODE" feature of Exim, # in which it uses the host's name as a suffix for the configuration file name. if [ "CONFIGURE_FILE_USE_NODE" = "yes" ]; then hostsuffix=.`uname -n` fi # Now find the configuration file name. This has got complicated because the # CONFIGURE_FILE value may now be a list of files. The one that is used is the # first one that exists. Mimic the code in readconf.c by testing first for the # suffixed file in each case. set `awk -F: '{ for (i = 1; i <= NF; i++) print $i }' <