1.\" $NetBSD: newsyslog.8,v 1.25 2002/10/02 15:20:10 wiz Exp $ 2.\" 3.\" Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. The name of the author may not be used to endorse or promote products 12.\" derived from this software without specific prior written permission 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24.\" 25.\" This file contains changes from the Open Software Foundation. 26.\" 27.\" Copyright 1988, 1989 by the Massachusetts Institute of Technology 28.\" 29.\" Permission to use, copy, modify, and distribute this software 30.\" and its documentation for any purpose and without fee is 31.\" hereby granted, provided that the above copyright notice 32.\" appear in all copies and that both that copyright notice and 33.\" this permission notice appear in supporting documentation, 34.\" and that the names of M.I.T. and the M.I.T. S.I.P.B. not be 35.\" used in advertising or publicity pertaining to distribution 36.\" of the software without specific, written prior permission. 37.\" M.I.T. and the M.I.T. S.I.P.B. make no representations about 38.\" the suitability of this software for any purpose. It is 39.\" provided "as is" without express or implied warranty. 40.\" 41.\" from FreeBSD: newsyslog.8,v 1.14.2.1 1999/02/25 18:38:33 wollman Exp 42.\" 43.Dd November 20, 1999 44.Dt NEWSYSLOG 8 45.Os 46.Sh NAME 47.Nm newsyslog 48.Nd maintain system log files to manageable sizes 49.Sh SYNOPSIS 50.Nm newsyslog 51.Op Fl nrsvF 52.Op Fl f Ar config_file 53.Op Pa file ... 54.Sh DESCRIPTION 55.Nm 56is a program that should be scheduled to run periodically by 57.Xr cron 8 . 58When it is executed it archives log files if necessary. 59If a log file is determined to require archiving, 60.Nm 61rearranges the files so that 62.Dq Va logfile 63is empty, 64.Dq Va logfile Ns Li \&.0 65has 66the last period's logs in it, 67.Dq Va logfile Ns Li \&.1 68has the next to last 69period's logs in it and so on, up to a user-specified number of 70archived logs. 71Optionally the archived logs can be compressed to save 72space. 73.Pp 74A log can be archived for three reasons: 75.Bl -enum -offset indent 76.It 77It is larger than the configured size (in kilobytes). 78.It 79A configured number of hours have elapsed since the log was last 80archived. 81.It 82The configured time for rotation of the log occurred within the last 60 83minutes. 84.El 85.Pp 86The granularity of 87.Nm 88is dependent on how often it is scheduled to run by 89.Xr cron 8 . 90It is recommended that 91.Nm 92be run once hourly. 93.Pp 94When starting up, 95.Nm 96reads in a configuration file to determine which logs may potentially 97be archived. 98By default, this configuration file is 99.Pa /etc/newsyslog.conf . 100Each line of the file contains information about a particular log file 101that should be handled by 102.Nm "" . 103Each line has six mandatory fields and three optional fields, with 104whitespace separating each field. 105Blank lines or lines beginning with 106.Dq # 107are ignored. 108The fields of the configuration file are as 109follows: 110.Pp 111.Bl -tag -width indent 112.It Ar logfile_name 113Name of the system log file to be archived. 114.It Ar owner:group 115This optional field specifies the owner and group for the archive file. 116The 117.Dq \&: 118is essential, even if the 119.Ar owner 120or 121.Ar group 122field is left blank. 123The field may be numeric, or a name which is present in 124.Pa /etc/passwd 125or 126.Pa /etc/group . 127For backward compatibility, 128.Dq \&\. 129is usable in lieu of 130.Dq \&: , 131however use of this feature is discouraged. 132.It Ar mode 133Specify the mode of the log file and archives. 134.It Ar ngen 135Specify the number of archive files to be kept 136besides the log file itself. 137.It Ar size 138When the size of the log file reaches 139.Ar size 140kilobytes, the log file will be trimmed as described above. 141If this field is replaced by an asterisk 142.Pq Ql \&* , 143then the size of the log file is not taken into account 144when determining when to trim the log file. 145.It Ar when 146The 147.Ar when 148field can consist of an interval, a specific time, or both. 149If the 150.Ar when 151field is an asterisk 152.Pq Ql \&* 153log rotation will depend only on the contents of the 154.Ar size 155field. 156Otherwise, the 157.Ar when 158field consists of an optional interval in hours, optionally followed 159by an 160.So Li \&@ Sc Ns No -sign 161and a time in a restricted 162.Tn ISO 8601 163format or by an 164.So Li \&$ Sc Ns No -sign 165and a time specification for logfile rotation at a fixed time once 166per day, per week or per month. 167.Pp 168If a time is specified, the log file will only be trimmed if 169.Nm 170is run within one hour of the specified time. 171If an 172interval is specified, the log file will be trimmed if that many hours have 173passed since the last rotation. 174When both a time and an interval are 175specified, the log will be trimmed if either condition is met. 176.Pp 177There is no provision for specification of a timezone. 178There is 179little point in specifying an explicit minutes or seconds component in 180the current implementation, since the only comparison is `within the 181hour'. 182.Pp 183.Em ISO 8601 restricted time format 184.Pp 185The lead-in character for a restricted 186.Tn ISO 8601 187time is 188an 189.So Li \&@ Sc Ns No -sign . 190The particular format of the time in restricted 191.Tn ISO 8601 192is: 193.Sm off 194.Oo 195.Oo 196.Oo 197.Oo 198.Oo 199.Va \&cc 200.Oc 201.Va \&yy 202.Oc 203.Va \&mm 204.Oc 205.Va \&dd 206.Oc 207.Oo 208.Li \&T 209.Oo 210.Va \&hh 211.Oo 212.Va \&mm 213.Oo 214.Va \&ss 215.Oc 216.Oc 217.Oc 218.Oc 219.Oc . 220.Sm on 221Optional date fields default to the appropriate component of the 222current date; optional time fields default to midnight; hence if today 223is January 22, 1999, the following date specifications are all 224equivalent: 225.Pp 226.Bl -item -compact -offset indent 227.It 228.Sq Li 19990122T000000 229.It 230.Sq Li 990122T000000 231.It 232.Sq Li 0122T000000 233.It 234.Sq Li 22T000000 235.It 236.Sq Li T000000 237.It 238.Sq Li T0000 239.It 240.Sq Li T00 241.It 242.Sq Li 22T 243.It 244.Sq Li \&T 245.It 246.Sq Li \& 247.El 248.Pp 249.Em Day, week and month time format 250.Pp 251The lead-in character for day, week and month specification is a 252.So Li \&$ Sc Ns No -sign . 253The particular format of day, week and month specification is: 254.Sm off 255.Oo 256.Va D\&hh 257.Oc , 258.Oo 259.Va W\&w 260.Oo 261.Va D\&hh 262.Oc 263.Oc 264and 265.Oo 266.Va M\&dd 267.Oo 268.Va D\&hh 269.Oc 270.Oc 271.Sm on 272respectively. 273Optional time fields default to midnight. 274The ranges for day and hour secifications are: 275.Pp 276.Bl -tag -width Ds -compact -offset indent 277.It Ar hh 278hours, range 0 ... 23 279.It Ar w 280day of week, range 0 ... 6, 0 = Sunday 281.It Ar dd 282day of month, range 1 ... 31, or the letter 283.Em L 284or 285.Em l 286to specify the last day of the month. 287.El 288.Pp 289Some examples: 290.Pp 291.Bl -tag -width Ds -compact -offset indent 292.It Ar $D0 293rotate every night at midnight 294.It Ar $D23 295rotate every day at 23:00 hr 296.It Ar $W0D23 297rotate every week on Sunday at 23:00 hr 298.It Ar $W5D16 299rotate every week on Friday at 16:00 hr 300.It Ar $MLD0 301rotate at the last day of every month at midnight 302.It Ar $M5D6 303rotate on every 5th day of month at 6:00 hr 304.El 305.Pp 306.It Ar flags 307This field specifies any special processing that is required. 308Individual 309flags and their meanings: 310.Bl -tag -width indent 311.It Sy - 312This flag means nothing - it is used as a spacer when no flags are set. 313.It Sy b 314The file is a binary file or is not in 315.Xr syslogd 8 316format: 317the 318.Tn ASCII 319message which 320.Nm 321inserts to indicate that the logs have been trimmed should not be included. 322.It Sy c 323Create an empty log file if none currently exists. 324.It Sy n 325No signal should be sent when the log is trimmed. 326.It Sy p 327The first historical log file (i.e. the historical log file with the suffix 328.Dq \.0 ) 329should not be compressed. 330.It Sy z 331Archived log files should be compressed with 332.Xr gzip 1 333to save space. 334.El 335.It Ar path_to_pid_file 336This optional field specifies 337the file name to read to find the daemon process id. 338If this field is present, a signal of type 339.Ar sigtype 340is sent the process id contained in this 341file. 342This field must start with 343.Sq / 344in order to be recognized properly. 345.It Ar sigtype 346This optional field specifies the type of signal to be sent to the daemon 347process. 348This may be a numeric or symbolic value. 349By default a SIGHUP (hang-up) will be sent. 350.El 351.Sh OPTIONS 352The following options can be used with newsyslog: 353.Bl -tag -width indent 354.It Fl f Ar config_file 355Use 356.Ar config_file 357instead of 358.Pa /etc/newsyslog.conf 359as the configuration file. 360.It Fl n 361Do not trim the logs, but print out would be done if this option were not 362specified: 363.Fl n 364implies 365.Fl v . 366.It Fl r 367Remove the restriction that 368.Nm 369must be running as root. 370When running as a regular user, 371.Nm 372will not be able to send a HUP signal to 373.Xr syslogd 8 , 374so this option should be used only when debugging or trimming user generated 375logs. 376.It Fl s 377Do not signal daemon processes. 378.It Fl v 379Run in verbose mode. 380In this mode each action that is taken will be printed. 381.It Fl F 382Force trimming of the logs, even if the trim conditions have not been met. 383This option is useful for diagnosing system problems by providing you with 384fresh logs. 385.El 386.Pp 387If additional command line arguments are given, 388.Nm 389will only examine log files that match those arguments; otherwise, it 390will examine all files listed in the configuration file. 391.Sh FILES 392.Bl -tag -width /etc/newsyslog.confxxxx -compact 393.It Pa /etc/newsyslog.conf 394.Nm 395configuration file. 396.El 397.Sh SEE ALSO 398.Xr gzip 1 , 399.Xr syslog 3 , 400.Xr syslogd 8 401.Sh AUTHORS 402.An Theodore Ts'o , 403MIT Project Athena 404.An Andrew Doran , 405The 406.Nx 407Project 408.Pp 409Copyright 1987, Massachusetts Institute of Technology 410.Pp 411Copyright 1999, 2000 Andrew Doran 412