From pa.dec.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!wuarchive!uunet!sparky!kent Thu May 2 20:27:59 PDT 1991 Article: 2292 of comp.sources.misc Path: pa.dec.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!wuarchive!uunet!sparky!kent From: scs@lokkur.dexter.mi.us (Steve Simmons) Newsgroups: comp.sources.misc Subject: v19i015: rotate_log - logfile management utility, Patch01 Message-ID: <1991May2.173743.14451@sparky.IMD.Sterling.COM> Date: 2 May 91 17:37:43 GMT Sender: kent@sparky.IMD.Sterling.COM (Kent Landfield) Organization: Sterling Software, IMD Lines: 290 Approved: kent@sparky.imd.sterling.com X-Checksum-Snefru: 19624e33 2728ce99 eb5459a0 8e3e95b0 Submitted-by: Steve Simmons Posting-number: Volume 19, Issue 15 Archive-name: rotate_log/patch01 Patch-To: rotate_log: Volume 17, Issue 77 This is patch01 to rotate_log. This patch fixes several bugs and adds a new feature to rotate_log. Owner/group/mode setting is now done right. Several errors in the man page have been corrected. A new '-s' feature has been added so that empty logs will not be rotated. Many thanks to Robert McGraw (mcgraw@sunspot.sunspot.noao.edu), David J. Fiander (david@scocan.sco.COM), Heiko Schlichting (heiko@methan.chemie.fu-berlin.de) and Rene' Seindal (seindal@skinfaxe.diku.dk) for fixes, comments and suggestions. To use -- go to wherever you archived the original and feed this file to patch. The original ReadMe file is below. --------------------- Tired of writing yet another log trimming sequence in yet another shell script? Then this little ditty is for you. It rotates logs, compresses them, cleans out the old logs, kills the oldest logs, lets you invoke custom commands along the way, complains politely if anything is wrong, and has a hot cup of coffee waiting for you in the morning. OK, it won't do the coffee. But it does everything else, and has managed to worm it's way into crontabs all over the joint. Today I was putting it in to clean Yet Another Log, and saw that our operators are using it, our other system programmer is using it, etc, etc. They're even reading the man page. Since it's such a success at work, it must be time to throw it to the wolves, er, world. Enjoy! Steve Simmons scs@lokkur.dexter.mi.us April 3, 1991 ----- *** ReadMe.old Tue Apr 30 22:16:26 1991 --- ReadMe Tue Apr 30 22:17:04 1991 *************** *** 14,16 **** --- 14,34 ---- Steve Simmons scs@lokkur.dexter.mi.us April 3, 1991 + + Notes on the patch release: + + This patch bring rotate_log to 0.7 and the man page to 1.4. This fix + patches several bugs in the initial (0.5) release. The parameterizing + of chmod/chown/chgrp introduced an interesting set of bugs reported by + many folks. Robert McGraw (mcgraw@sunspot.sunspot.noao.edu) and David + J. Fiander (david@scocan.sco.COM) sent detailed information and fixes. + Heiko Schlichting (heiko@methan.chemie.fu-berlin.de) sents some comments + and fixes for the man page. Fiander also suggested the "skip if + empty" (-s) switch to not rotate empty logs. That is implemented + here. + + Rene' Seindal (seindal@skinfaxe.diku.dk) sent some detailed commentary + on old sh versions and bsd. Those changes will be in a later release. + + Steve + April 27, 1991 *** rotate_log.old Tue Apr 30 22:16:27 1991 --- rotate_log Tue Apr 30 22:17:04 1991 *************** *** 10,15 **** --- 10,16 ---- # # -L Name of the directory 'log' is found in. # -n Number of backup copies to keep. + # -s Skip empty logs. # -c Compress the backup copy. # -B Dir to keep the backup copies in. # -b Name of backup copy. *************** *** 29,61 **** # redistributed provided this notice remains intact and any changes you # make are clearly marked as such. # ! # $Source: /home/lokkur/scs/src/rotate_log/RCS/rotate_log,v $ # ! # $Revision: 0.5 $ # ! # $Author: scs $ $Date: 91/04/03 19:49:00 $ # # $State: Exp $ $Locker: $ # # $Log: rotate_log,v $ # Revision 0.5 91/04/03 19:49:00 scs # Parameterized locations of chmod, chgrp, chown. # - # Revision 0.4 89/12/12 09:35:59 scs - # Bug fixes to pick up more defaults. - # - # Revision 0.3 89/12/11 21:34:25 scs - # Broke out commands separately to avoid ksh wierdness. Ported - # to system V.2 sh, ksh. Removed some BSDisms that makes it more - # portable. - # - # Revision 0.2 89/12/11 20:53:51 scs - # Improved error checking on source directory. Corrected erroneous - # error message. - # - # Revision 0.1 89/12/11 19:39:31 scs - # Initial revision. - # SCRIPT=`basename $0` # # Commonly used commands --- 30,54 ---- # redistributed provided this notice remains intact and any changes you # make are clearly marked as such. # ! # $Source: /home/lokkur/scs/src/rotate_log/rotate_log/RCS/rotate_log,v $ # ! # $Revision: 0.7 $ # ! # $Author: scs $ $Date: 91/04/30 22:10:10 $ # # $State: Exp $ $Locker: $ # # $Log: rotate_log,v $ + # Revision 0.7 91/04/30 22:10:10 scs + # Aded -s switch. + # + # Revision 0.6 91/04/27 16:16:59 scs + # Fixed bug with -b/-n combo losing arguements. Patch supplied by + # Michael Bredeweg (...clif!comnet!mike). + # # Revision 0.5 91/04/03 19:49:00 scs # Parameterized locations of chmod, chgrp, chown. # SCRIPT=`basename $0` # # Commonly used commands *************** *** 80,85 **** --- 73,79 ---- BACKUP_MODE="" BACKUP_OWNER="" BACKUP_GROUP="" + SKIP_FLAG="false" # # Basic switch parsing. Right now, this forces us to use whitespace # between switch char and actual execution. Whenever we get data *************** *** 135,140 **** --- 129,136 ---- BACKUP_COUNT="$2" shift ;; + -s ) SKIP_FLAG="true" + ;; -c ) COMPRESS="compress" ;; -m ) if [ "$2" = "" ] ; then *************** *** 283,288 **** --- 279,293 ---- exit 0 fi # + # If the log is empty and the skip flag (-s) is set, do nothing. + # + if [ "${SKIP_FLAG}" = "true" ] ; then + set `wc -c ${SOURCE_PATH}` + if [ 0 = $1 ] ; then + exit 0 + fi + fi + # # Make sure root operations are only run by root # if [ "${BACKUP_OWNER}" != "" -o "${SOURCE_OWNER}" != "" -o "${BACKUP_GROUP}" != "" -o "${SOURCE_GROUP}" != "" ] *************** *** 314,319 **** --- 319,325 ---- exit 0 fi OLDEST="${1}" + NEXT="${1}" shift while [ "$1" != "" ] ; do NEXT="${1}" *** rotate_log.8.old Tue Apr 30 22:16:27 1991 --- rotate_log.8 Tue Apr 30 22:17:04 1991 *************** *** 1,23 **** .\" Manual page for rotate_log .\" ! .\" $Source: /home/lokkur/scs/src/rotate_log/RCS/rotate_log.8,v $ .\" ! .\" $Revision: 1.3 $ .\" ! .\" $Author: scs $ $Date: 89/12/11 17:54:30 $ .\" ! .\" $State: Exp $ $Locker: scs $ .\" .\" $Log: rotate_log.8,v $ ."\ Revision 1.3 89/12/11 17:54:30 scs ."\ Added prolog and postlog commands. ."\ - ."\ Revision 1.2 89/12/11 17:34:46 scs - ."\ Corrected minor format errors. - ."\ - ."\ Revision 1.1 89/12/11 17:29:36 scs - ."\ Initial revision - ."\ .TH ROTATE_LOG 8 89/12/11 .SH NAME rotate_log \- rotate logfiles, removing the oldest --- 1,22 ---- .\" Manual page for rotate_log .\" ! .\" $Source: /home/lokkur/scs/src/rotate_log/rotate_log/RCS/rotate_log.8,v $ .\" ! .\" $Revision: 1.4 $ .\" ! .\" $Author: scs $ $Date: 91/04/27 16:26:23 $ .\" ! .\" $State: Exp $ $Locker: $ .\" .\" $Log: rotate_log.8,v $ + .\" Revision 1.4 91/04/27 16:26:23 scs + .\" Corrected references to prolog/postlog in the man page. Many thanks + .\" to Heiko Schlichting (heiko@methan.chemie.fu-berlin.de) for pointing + .\" out the problems. + .\" ."\ Revision 1.3 89/12/11 17:54:30 scs ."\ Added prolog and postlog commands. ."\ .TH ROTATE_LOG 8 89/12/11 .SH NAME rotate_log \- rotate logfiles, removing the oldest *************** *** 111,117 **** (this option is only available to .I root ). .TP ! .B "\-O group" Set the group membership of .I logfile.0 to --- 110,116 ---- (this option is only available to .I root ). .TP ! .B "\-G group" Set the group membership of .I logfile.0 to *************** *** 130,136 **** has spaces, blanks, or metacharacters they must be quoted. .TP .B "\-E postlog_command" ! .I prolog_command is a command to be executed immediately after emptying .I logfile Note it is only executed if --- 129,135 ---- has spaces, blanks, or metacharacters they must be quoted. .TP .B "\-E postlog_command" ! .I postlog_command is a command to be executed immediately after emptying .I logfile Note it is only executed if *************** *** 137,143 **** .I logfile is successfully emptied. Note also that if ! .I prolog_command has spaces, blanks, or metacharacters they must be quoted. .PP Note that the mode and ownership settings apply only the the newly --- 136,142 ---- .I logfile is successfully emptied. Note also that if ! .I postlog_command has spaces, blanks, or metacharacters they must be quoted. .PP Note that the mode and ownership settings apply only the the newly exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.