1.\" $NetBSD: newsyslog.8,v 1.36 2007/12/21 19:45:33 snj 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 December 21, 2007 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.Oo 255.Va D\&hh 256.Oc , 257.Sm off 258.Oo 259.Va W\&w 260.Oo 261.Va D\&hh 262.Oc 263.Oc 264.Sm on 265and 266.Sm off 267.Oo 268.Va M\&dd 269.Oo 270.Va D\&hh 271.Oc 272.Oc 273.Sm on 274respectively. 275Optional time fields default to midnight. 276The ranges for day and hour specifications are: 277.Pp 278.Bl -tag -width Ds -compact -offset indent 279.It Ar hh 280hours, range 0 ... 23 281.It Ar w 282day of week, range 0 ... 6, 0 = Sunday 283.It Ar dd 284day of month, range 1 ... 31, or the letter 285.Em L 286or 287.Em l 288to specify the last day of the month. 289.El 290.Pp 291Some examples: 292.Pp 293.Bl -tag -width Ds -compact -offset indent 294.It Ar $D0 295rotate every night at midnight 296.It Ar $D23 297rotate every day at 23:00 hr 298.It Ar $W0D23 299rotate every week on Sunday at 23:00 hr 300.It Ar $W5D16 301rotate every week on Friday at 16:00 hr 302.It Ar $MLD0 303rotate at the last day of every month at midnight 304.It Ar $M5D6 305rotate on every 5th day of month at 6:00 hr 306.El 307.Pp 308.It Ar flags 309This field specifies any special processing that is required. 310These flags are parsed in a case insensitive manner. 311Individual 312flags and their meanings: 313.Bl -tag -width indent 314.It Sy - 315This flag means nothing - it is used as a spacer when no flags are set. 316.It Sy b 317The file is a binary file or is not in 318.Xr syslogd 8 319format: 320the 321.Tn ASCII 322message which 323.Nm 324inserts to indicate that the logs have been trimmed should not be included. 325.It Sy c 326Create an empty log file if none currently exists. 327.It Sy n 328No signal should be sent when the log is trimmed. 329.It Sy p 330The first historical log file (i.e. the historical log file with the suffix 331.Dq \.0 ) 332should not be compressed. 333.It Sy j 334Archived log files should be compressed with 335.Xr bzip2 1 336to save space. 337.It Sy z 338Archived log files should be compressed with 339.Xr gzip 1 340to save space. 341.El 342.It Ar path_to_pid_file 343This optional field specifies 344the file name to read to find the daemon process id. 345If this field is missing, it defaults to the 346.Pa /var/run/syslogd.pid 347file. 348A signal of type 349.Ar sigtype 350is sent to the process id contained in this 351.Ar path_to_pid_file 352file. 353This field must start with 354.Sq / 355in order to be recognized properly. 356.It Ar sigtype 357This optional field specifies the type of signal to be sent to the daemon 358process. 359This may be a numeric or symbolic value. 360By default a SIGHUP (hang-up) will be sent. 361.El 362.Sh OPTIONS 363The following options can be used with newsyslog: 364.Bl -tag -width indent 365.It Fl f Ar config_file 366Use 367.Ar config_file 368instead of 369.Pa /etc/newsyslog.conf 370as the configuration file. 371.It Fl n 372Do not trim the logs, but print out what would be done if this option were not 373specified: 374.Fl n 375implies 376.Fl v . 377.It Fl r 378Remove the restriction that 379.Nm 380must be running as root. 381When running as a regular user, 382.Nm 383will not be able to send a HUP signal to 384.Xr syslogd 8 , 385so this option should be used only when debugging or trimming user generated 386logs. 387.It Fl s 388Do not signal daemon processes. 389.It Fl v 390Run in verbose mode. 391In this mode each action that is taken will be printed. 392.It Fl F 393Force trimming of the logs, even if the trim conditions have not been met. 394This option is useful for diagnosing system problems by providing you with 395fresh logs. 396.El 397.Pp 398If additional command line arguments are given, 399.Nm 400will only examine log files that match those arguments; otherwise, it 401will examine all files listed in the configuration file. 402.Sh FILES 403.Bl -tag -width /etc/newsyslog.confxxxx -compact 404.It Pa /etc/newsyslog.conf 405.Nm 406configuration file. 407.El 408.Sh SEE ALSO 409.Xr bzip2 1 , 410.Xr gzip 1 , 411.Xr syslog 3 , 412.Xr syslogd 8 413