1.\" $NetBSD: newsyslog.8,v 1.22 2002/03/29 02:45:54 heinz 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. If a log file 59is 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. Optionally the archived logs can be compressed to save 71space. 72.Pp 73A log can be archived for three reasons: 74.Bl -enum -offset indent 75.It 76It is larger than the configured size (in kilobytes). 77.It 78A configured number of hours have elapsed since the log was last 79archived. 80.It 81The configured time for rotation of the log occurred within the last 60 82minutes. 83.El 84.Pp 85The granularity of 86.Nm 87is dependent on how often it is scheduled to run by 88.Xr cron 8 . 89It is recommended that 90.Nm 91be run once hourly. 92.Pp 93When starting up, 94.Nm 95reads in a configuration file to determine which logs may potentially 96be archived. 97By default, this configuration file is 98.Pa /etc/newsyslog.conf . 99Each line of the file contains information about a particular log file 100that should be handled by 101.Nm "" . 102Each line has six mandatory fields and three optional fields, with 103whitespace separating each field. Blank lines or lines beginning with 104``#'' are ignored. The fields of the configuration file are as 105follows: 106.Pp 107.Bl -tag -width indent 108.It Ar logfile_name 109Name of the system log file to be archived. 110.It Ar owner:group 111This optional field specifies the owner and group for the archive file. 112The ":" is essential, even if the 113.Ar owner 114or 115.Ar group 116field is left blank. The field may be numeric, or a name which is 117present in 118.Pa /etc/passwd 119or 120.Pa /etc/group . 121For backward compatibility, "." is useable in lieu of ":", however use of 122this feature is discouraged. 123.It Ar mode 124Specify the mode of the log file and archives. 125.It Ar ngen 126Specify the number of archive files to be kept 127besides the log file itself. 128.It Ar size 129When the size of the log file reaches 130.Ar size 131kilobytes, the log file will be trimmed as described above. If this field 132is replaced by an asterisk 133.Pq Ql \&* , 134then the size of the log file is not taken into account 135when determining when to trim the log file. 136.It Ar when 137The 138.Ar when 139field can consist of an interval, a specific time, or both. If 140the 141.Ar when 142field is an asterisk 143.Pq Ql \&* 144log rotation will depend only on the contents of the 145.Ar size 146field. 147Otherwise, the 148.Ar when 149field consists of an optional interval in hours, optionally followed 150by an 151.So Li \&@ Sc Ns No -sign 152and a time in a restricted 153.Tn ISO 8601 154format or by an 155.So Li \&$ Sc Ns No -sign 156and a time specification for logfile rotation at a fixed time once 157per day, per week or per month. 158.Pp 159If a time is specified, the log file will only be trimmed if 160.Nm 161is run within one hour of the specified time. If an 162interval is specified, the log file will be trimmed if that many hours have 163passed since the last rotation. When both a time and an interval are 164specified, the log will be trimmed if either condition is met. 165.Pp 166There is no provision for specification of a timezone. There is 167little point in specifying an explicit minutes or seconds component in 168the current implementation, since the only comparison is `within the 169hour'. 170.Pp 171.Em ISO 8601 restricted time format 172.Pp 173The lead-in character for a restricted 174.Tn ISO 8601 175time is 176an 177.So Li \&@ Sc Ns No -sign . 178The particular format of the time in restricted 179.Tn ISO 8601 180is: 181.Sm off 182.Oo 183.Oo 184.Oo 185.Oo 186.Oo 187.Va \&cc 188.Oc 189.Va \&yy 190.Oc 191.Va \&mm 192.Oc 193.Va \&dd 194.Oc 195.Oo 196.Li \&T 197.Oo 198.Va \&hh 199.Oo 200.Va \&mm 201.Oo 202.Va \&ss 203.Oc 204.Oc 205.Oc 206.Oc 207.Oc . 208.Sm on 209Optional date fields default to the appropriate component of the 210current date; optional time fields default to midnight; hence if today 211is January 22, 1999, the following date specifications are all 212equivalent: 213.Pp 214.Bl -item -compact -offset indent 215.It 216.Sq Li 19990122T000000 217.It 218.Sq Li 990122T000000 219.It 220.Sq Li 0122T000000 221.It 222.Sq Li 22T000000 223.It 224.Sq Li T000000 225.It 226.Sq Li T0000 227.It 228.Sq Li T00 229.It 230.Sq Li 22T 231.It 232.Sq Li \&T 233.It 234.Sq Li \& 235.El 236.Pp 237.Em Day, week and month time format 238.Pp 239The lead-in character for day, week and month specification is a 240.So Li \&$ Sc Ns No -sign . 241The particular format of day, week and month specification is: 242.Sm off 243.Oo 244.Va D\&hh 245.Oc , 246.Oo 247.Va W\&w 248.Oo 249.Va D\&hh 250.Oc 251.Oc 252and 253.Oo 254.Va M\&dd 255.Oo 256.Va D\&hh 257.Oc 258.Oc 259.Sm on 260respectively. 261Optional time fields default to midnight. 262The ranges for day and hour secifications are: 263.Pp 264.Bl -tag -width Ds -compact -offset indent 265.It Ar hh 266hours, range 0 ... 23 267.It Ar w 268day of week, range 0 ... 6, 0 = Sunday 269.It Ar dd 270day of month, range 1 ... 31, or the letter 271.Em L 272or 273.Em l 274to specify the last day of the month. 275.El 276.Pp 277Some examples: 278.Pp 279.Bl -tag -width Ds -compact -offset indent 280.It Ar $D0 281rotate every night at midnight 282.It Ar $D23 283rotate every day at 23:00 hr 284.It Ar $W0D23 285rotate every week on Sunday at 23:00 hr 286.It Ar $W5D16 287rotate every week on Friday at 16:00 hr 288.It Ar $MLD0 289rotate at the last day of every month at midnight 290.It Ar $M5D6 291rotate on every 5th day of month at 6:00 hr 292.El 293.Pp 294.It Ar flags 295This field specifies any special processing that is required. Individual 296flags and their meanings: 297.Bl -tag -width indent 298.It Sy - 299This flag means nothing - it is used as a spacer when no flags are set. 300.It Sy b 301The file is a binary file or is not in 302.Xr syslogd 8 303format: 304the 305.Tn ASCII 306message which 307.Nm 308inserts to indicate that the logs have been trimmed should not be included. 309.It Sy c 310Create an empty log file if none currently exists. 311.It Sy n 312No signal should be sent when the log is trimmed. 313.It Sy p 314The first historical log file (i.e. the historical log file with the suffix 315``.0'') should not be compressed. 316.It Sy z 317Archived log files should be compressed with 318.Xr gzip 1 319to save space. 320.El 321.It Ar path_to_pid_file 322This optional field specifies 323the file name to read to find the daemon process id. If this 324field is present, a signal of type 325.Ar sigtype 326is sent the process id contained in this 327file. This field must start with "/" in order to be recognized 328properly. 329.It Ar sigtype 330This optional field specifies the type of signal to be sent to the daemon 331process. This may be a numeric or symbolic value. By default 332a SIGHUP (hang-up) will be sent. 333.El 334.Sh OPTIONS 335The following options can be used with newsyslog: 336.Bl -tag -width indent 337.It Fl f Ar config_file 338Use 339.Ar config_file 340instead of 341.Pa /etc/newsyslog.conf 342as the configuration file. 343.It Fl n 344Do not trim the logs, but print out would be done if this option were not 345specified: 346.Fl n 347implies 348.Fl v . 349.It Fl r 350Remove the restriction that 351.Nm 352must be running as root. When running as a regular user, 353.Nm 354will not be able to send a HUP signal to 355.Xr syslogd 8 , 356so this option should be used only when debugging or trimming user generated 357logs. 358.It Fl s 359Do not signal daemon processes. 360.It Fl v 361Run in verbose mode. In this mode each action that is taken will be printed. 362.It Fl F 363Force trimming of the logs, even if the trim conditions have not been met. 364This option is useful for diagnosing system problems by providing you with 365fresh logs. 366.El 367.Pp 368If additional command line arguments are given, 369.Nm 370will only examine log files that match those arguments; otherwise, it 371will examine all files listed in the configuration file. 372.Sh FILES 373.Bl -tag -width /etc/newsyslog.confxxxx -compact 374.It Pa /etc/newsyslog.conf 375.Nm 376configuration file. 377.El 378.Sh SEE ALSO 379.Xr gzip 1 , 380.Xr syslog 3 , 381.Xr syslogd 8 382.Sh AUTHORS 383.An Theodore Ts'o , 384MIT Project Athena 385.An Andrew Doran , 386The 387.Nx 388Project 389.Pp 390Copyright 1987, Massachusetts Institute of Technology 391.Pp 392Copyright 1999, 2000 Andrew Doran 393