[syslog-ng]persistent link to current file

Ed Ravin syslog-ng@lists.balabit.hu
Wed, 14 Jan 2004 15:28:22 -0500


--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Jan 13, 2004 at 01:39:20PM -0500, Gainey, Joe (AT-Atlanta) wrote:

> it would be nice if there was an option:
> 
> destination d_default {
>    file("/var/adm/messages.$YEAR.$MONTH.$DAY"
> soft_link("/var/adm/messages")) ;
> } ;

That is a nice idea!  But until someone writes a patch for it, you might
want to try my "loglinks" script (see attached) which should simplify
the process.  I wrote it for a central syslog server so that I could
do this:

     loglinks /log/hosts  /log/archive/hosts/BASENAME/%Y/%m/BASENAME.%Y.%m.%d     host1 host2 [..]

Which means that /log/hosts/HOSTNAME is always pointing to the right
file in /log/archive/hosts/HOSTNAME/........

In your environment, I think the following work if you run it just after
midnight out of cron:

  loglinks /var/adm /var/adm/BASENAME.%Y.%m.%d messages notices maillog

Assuming that you're symlinking to those three logfiles.

Experiment with it by setting "LOGLINKS_DEBUG=YES" in your environment
and it'll just print the symlinks it would create instead of actually
calling "ln -s".

	-- Ed

--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=loglinks

#!/bin/sh

set -u

if [ ${LOGLINKS_DEBUG:-no} = YES ]
then
	DEBUG="echo"
else
	DEBUG=""
fi

bomb() {
	echo $1
	exit 23
}

USAGE="Usage: loglinks /today-dir path/with/%Y/%m/%d/BASENAME.%Y.%m.%d basename [...]"

TODAYDIR=${1:?$USAGE} ; shift
DATESTR=${1:?$USAGE}  ; shift

cd $TODAYDIR || bomb "$0: cannot cd to top-level dir: $TODAYDIR"

while [ $# -gt 0 ]
do
	logname=$1; shift
	format=$(echo $DATESTR | sed -e "s/BASENAME/$logname/g")
	format=$(date "+$format")
	$DEBUG rm -f $TODAYDIR/$logname
	if [ ! -f $format -a -n "$DEBUG" ]
	then
		echo "$0: warning: file not found, making symlink anyway: $format"
	fi
	$DEBUG ln -s $format $TODAYDIR/$logname
done


--RnlQjJ0d97Da+TV1--