Bug#309188: savelog patch: configurable date format
On Sat, Oct 20, 2007 at 02:52:16PM +0200, Lasse Karstensen wrote: Attached is a simple patch that let you choose the date format used for -d on the command line. Using mmddHHMMSS seems to noisy, and with this patch both mmdd and (what we want) -mm-dd is possible. I believe this patch must have been created for a version of debian-utils older than 2.17.4, because it breaks completely in combination with the patch for #401143, introduced in 2.17.4. That patch assumes that the suffix consists of exactly 14 numeric characters. Obviously, this is not always the case when users are allowed to create arbitrary suffixes using -D. I have attached a patch which (as far as I can see) removes all assumptions about the format of the date string. It also solves the problem with gzip errors from the initial rotation, as mentioned by Paul Slootman earlier. I also hard coded .gz and .bz2 in there, so people can change from gz to bz2 (or vice versa) without double-compressing logs. $DOT_Z is also matched, to minimize the breakage in case of new formats being added in the future. Note that this patch might cause odd behaviour if one log filename is a prefix of another. For example, when rotating the file foo, foo.bar will also be affected, since savelog doesn't know if bar is part of the date string supplied with -D or not. I am not aware of log files which would be affected, but didn't investigate the matter very throughly. I considered a hack with limiting the matching to the length of $DATUM, but that would assume that the format string supplied with -C always creates dates of equal length, and we don't know that. Besides, it would still break if $DATUM had the same amount of characters as bar. Also note that DATUM=`date +$OPTARG` doesn't quote $OPTARG, and thus requires the string supplied to -D to be escaped twice if it contains spaces or other weird characters. I didn't patch this, because I'm not sure if the possibility to use -D %Y-%m-%d -d yesterday to get yesterdays date (useful when savelog is ran right after midnight) is a feature or a bug ;-) -- Knut Auvor Grythe --- savelog.orig2007-10-29 20:28:36.0 +0100 +++ savelog 2007-11-09 13:15:15.0 +0100 @@ -265,16 +265,27 @@ # compress the old uncompressed log if needed if test -n $datum test -n $COMPRESS; then - $COMPRESS $COMPRESS_OPTS -- $newname.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] + + # Loop through all matching files + for f in $newname.*; do + + # Skip if glob didn't expand (this means no file was found) + test $f = $newname.* continue + + # Skip if file is already compressed + echo $f | egrep (\\.gz|\\.bz2|\\$DOT_Z)\$ /dev/null continue + + $COMPRESS $COMPRESS_OPTS -- $f + done fi # remove old files if so desired if [ -n $forceclean ]; then cycle=$(( $count - 1)) if [ -z $COMPRESS ]; then - rm -f -- `ls -t -- $newname.[0-9]* | sed -e 1,${cycle}d` + rm -f -- `ls -t -- $newname.* | sed -e 1,${cycle}d` else - rm -f -- `ls -t -- $newname.[0-9]*$DOT_Z | sed -e 1,${cycle}d` + rm -f -- `ls -t -- $newname.*$DOT_Z | sed -e 1,${cycle}d` fi fi
Bug#309188: savelog patch: configurable date format
Package: debianutils Version: 2.15.2 Severity: wishlist Hello. Attached is a simple patch that let you choose the date format used for -d on the command line. Using mmddHHMMSS seems to noisy, and with this patch both mmdd and (what we want) -mm-dd is possible. -- Lasse Karstensen --- debianutils-2.15.2/savelog 2005-02-28 04:37:52.0 +0100 +++ savelog 2007-10-20 14:35:14.0 +0200 @@ -21,6 +21,7 @@ # -r rolldir- use rolldir instead of . to roll files # -C- force cleanup of cycled logfiles # -d- use standard date for rolling +# -f- override date format for -d # -t- touch file # -l- don't compress any log files(default: compress) # -p- preserve mode/user/group of original file @@ -107,6 +108,7 @@ echo -r rolldir - use rolldir instead of . to roll files echo -C - force cleanup of cycled logfiles echo -d - use standard date for rolling +echo -f - override date format for -d echo -t - touch file echo -l - don't compress any log files (default: compress) echo -p - preserve mode/user/group of original file @@ -131,7 +133,7 @@ } -while getopts m:u:g:c:r:Cdtlphjnq opt ; do +while getopts m:u:g:c:r:Cdf:tlphjnq opt ; do case $opt in m) mode=$OPTARG ;; u) user=$OPTARG ;; @@ -140,6 +142,7 @@ r) rolldir=$OPTARG ;; C) forceclean=1 ;; d) datum=1 ;; + f) DATUM=`date +$OPTARG` ;; t) touch=1 ;; j) COMPRESS=bzip2 -9f ; DOT_Z=.bz2 ;; l) COMPRESS= ;;
Bug#309188: savelog patch: configurable date format
On Sat, Oct 20, 2007 at 02:52:16PM +0200, Lasse Karstensen wrote: Attached is a simple patch that let you choose the date format used for -d on the command line. Using mmddHHMMSS seems to noisy, and with this patch both mmdd and (what we want) -mm-dd is possible. +#-f- override date format for -d How about -D instead? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#309188: savelog patch: configurable date format
Clint Adams: On Sat, Oct 20, 2007 at 02:52:16PM +0200, Lasse Karstensen wrote: Attached is a simple patch that let you choose the date format used for -d on the command line. Using mmddHHMMSS seems to noisy, and with this patch both mmdd and (what we want) -mm-dd is possible. +# -f- override date format for -d How about -D instead? Works for me. New patch attached. -- Lasse Karstensen --- debianutils-2.15.2/savelog 2005-02-28 04:37:52.0 +0100 +++ savelog 2007-10-20 14:35:14.0 +0200 @@ -21,6 +21,7 @@ # -r rolldir- use rolldir instead of . to roll files # -C- force cleanup of cycled logfiles # -d- use standard date for rolling +# -D- override date format for -d # -t- touch file # -l- don't compress any log files(default: compress) # -p- preserve mode/user/group of original file @@ -107,6 +108,7 @@ echo -r rolldir - use rolldir instead of . to roll files echo -C - force cleanup of cycled logfiles echo -d - use standard date for rolling +echo -D - override date format for -d echo -t - touch file echo -l - don't compress any log files (default: compress) echo -p - preserve mode/user/group of original file @@ -131,7 +133,7 @@ } -while getopts m:u:g:c:r:Cdtlphjnq opt ; do +while getopts m:u:g:c:r:CdD:tlphjnq opt ; do case $opt in m) mode=$OPTARG ;; u) user=$OPTARG ;; @@ -140,6 +142,7 @@ r) rolldir=$OPTARG ;; C) forceclean=1 ;; d) datum=1 ;; + D) DATUM=`date +$OPTARG` ;; t) touch=1 ;; j) COMPRESS=bzip2 -9f ; DOT_Z=.bz2 ;; l) COMPRESS= ;;