1.\" $NetBSD: newsyslog.8,v 1.46 2021/03/02 10:17:25 uwe 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 March 1, 2021 44.Dt NEWSYSLOG 8 45.Os 46.Sh NAME 47.Nm newsyslog , 48.Nm newsyslog.conf 49.Nd maintain system log files to manageable sizes 50.Sh SYNOPSIS 51.Nm newsyslog 52.Op Fl Fnrsv 53.Op Fl f Ar config_file 54.Op Pa file ... 55.Sh DESCRIPTION 56.Nm 57is a program that should be scheduled to run periodically by 58.Xr cron 8 . 59When it is executed it archives log files if necessary. 60If a log file is determined to require archiving, 61.Nm 62rearranges the files so that 63.Dq Va logfile 64is empty, 65.Dq Va logfile Ns Li \&.0 66has 67the last period's logs in it, 68.Dq Va logfile Ns Li \&.1 69has the next to last 70period's logs in it and so on, up to a user-specified number of 71archived logs. 72Optionally the archived logs can be compressed to save 73space. 74.Pp 75A log can be archived for three reasons: 76.Bl -enum -offset indent 77.It 78It is larger than the configured size (in kilobytes). 79.It 80A configured number of hours have elapsed since the log was last 81archived. 82.It 83The configured time for rotation of the log occurred within the last 60 84minutes. 85.El 86.Pp 87The granularity of 88.Nm 89is dependent on how often it is scheduled to run by 90.Xr cron 8 . 91It is recommended that 92.Nm 93be run once hourly. 94.Pp 95When starting up, 96.Nm 97reads in a configuration file to determine which logs may potentially 98be archived. 99By default, this configuration file is 100.Pa /etc/newsyslog.conf . 101Each line of the file contains information about a particular log file 102that should be handled by 103.Nm . 104Each line has six mandatory fields and three optional fields, with 105whitespace separating each field. 106Blank lines or lines beginning with 107.Ql # 108are ignored. 109The fields of the configuration file are as 110follows: 111.Bl -tag -width Fl 112.It Ar logfile_name 113Name of the system log file to be archived. 114.It Ar owner Ns Li \&: Ns Ar group 115This optional field specifies the owner and group for the archive file. 116The 117.Ql \&: 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.Ql \&. 129is usable in lieu of 130.Ql \&: , 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 ISO 8601 format or by an 162.So Li \&$ Sc Ns No -sign 163and a time specification for logfile rotation at a fixed time once 164per day, per week or per month. 165.Pp 166If a time is specified, the log file will only be trimmed if 167.Nm 168is run within one hour of the specified time. 169If an 170interval is specified, the log file will be trimmed if that many hours have 171passed since the last rotation. 172When both a time and an interval are 173specified, the log will be trimmed if either condition is met. 174.Pp 175There is no provision for specification of a timezone. 176There is 177little point in specifying an explicit minutes or seconds component in 178the current implementation, since the only comparison is `within the 179hour'. 180.Pp 181.Em ISO 8601 restricted time format 182.Pp 183The lead-in character for a restricted ISO 8601 time is an 184.So Li \&@ Sc Ns No -sign . 185The particular format of the time in restricted ISO 8601 is: 186.Sm off 187.Oo 188.Oo 189.Oo 190.Oo 191.Oo 192.Va \&cc 193.Oc 194.Va \&yy 195.Oc 196.Va \&mm 197.Oc 198.Va \&dd 199.Oc 200.Oo 201.Li \&T 202.Oo 203.Va \&hh 204.Oo 205.Va \&mm 206.Oo 207.Va \&ss 208.Oc 209.Oc 210.Oc 211.Oc 212.Oc . 213.Sm on 214Optional date fields default to the appropriate component of the 215current date; optional time fields default to midnight; hence if today 216is January 22, 1999, the following date specifications are all 217equivalent: 218.Pp 219.Bl -item -compact -offset indent 220.It 221.Sq Li 19990122T000000 222.It 223.Sq Li 990122T000000 224.It 225.Sq Li 0122T000000 226.It 227.Sq Li 22T000000 228.It 229.Sq Li T000000 230.It 231.Sq Li T0000 232.It 233.Sq Li T00 234.It 235.Sq Li 22T 236.It 237.Sq Li \&T 238.It 239.Sq Li \& 240.El 241.Pp 242.Em Day, week and month time format 243.Pp 244The lead-in character for day, week and month specification is a 245.So Li \&$ Sc Ns No -sign . 246The particular format of day, week and month specification is: 247.Oo 248.Li D Ns Va \&hh 249.Oc , 250.Sm off 251.Oo 252.Li W Ns Va \&w 253.Oo 254.Li D Ns Va \&hh 255.Oc 256.Oc 257.Sm on 258and 259.Sm off 260.Oo 261.Li M Ns Va \&dd 262.Oo 263.Li D Ns Va \&hh 264.Oc 265.Oc 266.Sm on 267respectively. 268Optional time fields default to midnight. 269The ranges for day and hour specifications are: 270.Pp 271.Bl -tag -width Ds -compact -offset indent 272.It Ar hh 273hours, range 0 ... 23 274.It Ar w 275day of week, range 0 ... 6, 0 = Sunday 276.It Ar dd 277day of month, range 1 ... 31, or the letter 278.Ql L 279or 280.Ql l 281to specify the last day of the month. 282.El 283.Pp 284Some examples: 285.Pp 286.Bl -tag -width Ds -compact -offset indent 287.It Li $D0 288rotate every night at midnight 289.It Li $D23 290rotate every day at 23:00 hr 291.It Li $W0D23 292rotate every week on Sunday at 23:00 hr 293.It Li $W5D16 294rotate every week on Friday at 16:00 hr 295.It Li $MLD0 296rotate at the last day of every month at midnight 297.It Li $M5D6 298rotate on every 5th day of month at 6:00 hr 299.El 300.It Ar flags 301This field specifies any special processing that is required. 302These flags are parsed in a case insensitive manner. 303Individual 304flags and their meanings: 305.Bl -tag -width indent 306.It Ic \- 307This flag means nothing \(em it is used as a spacer when no flags are set. 308.It Ic b 309The file is a binary file or is not in 310.Xr syslogd 8 311format: the ASCII message which 312.Nm 313inserts to indicate that the logs have been trimmed should not be included. 314.It Ic c 315Create an empty log file if none currently exists. 316.It Ic e 317Do not rotate log file with zero size (empty). 318This flag is mostly usable in conjunction with 319.Ic b 320flag that prevents 321.Nm 322from inserting an ASCII informational message. 323.It Ic j 324Archived log files should be compressed with 325.Xr bzip2 1 326to save space. 327.It Ic n 328No signal should be sent when the log is trimmed. 329.It Ic p 330The first historical log file (i.e. the historical log file with the suffix 331.Ql \.0 ) 332should not be compressed. 333.It Ic x 334Archived log files should be compressed with 335.Xr xz 1 336to save space. 337.It Ic 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.Ql / 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 361.Dv SIGHUP 362(hang-up) will be sent. 363.El 364.Sh OPTIONS 365The following options can be used with newsyslog: 366.Bl -tag -width indent 367.It Fl F 368Force trimming of the logs, even if the trim conditions have not been met. 369This option is useful for diagnosing system problems by providing you with 370fresh logs. 371.It Fl f Ar config_file 372Use 373.Ar config_file 374instead of 375.Pa /etc/newsyslog.conf 376as the configuration file. 377.It Fl n 378Do not trim the logs, but print out what would be done if this option were not 379specified: 380.Fl n 381implies 382.Fl v . 383.It Fl r 384Remove the restriction that 385.Nm 386must be running as root. 387When running as a regular user, 388.Nm 389will not be able to send a 390.Dv SIGHUP 391signal to 392.Xr syslogd 8 , 393so this option should be used only when debugging or trimming user generated 394logs. 395.It Fl s 396Do not signal daemon processes. 397.It Fl v 398Run in verbose mode. 399In this mode each action that is taken will be printed. 400.El 401.Pp 402If additional command line arguments are given, 403.Nm 404will only examine log files that match those arguments; otherwise, it 405will examine all files listed in the configuration file. 406.Sh FILES 407.Bl -tag -width /etc/newsyslog.confxxxx -compact 408.It Pa /etc/newsyslog.conf 409.Nm 410configuration file. 411.El 412.Sh SEE ALSO 413.Xr bzip2 1 , 414.Xr gzip 1 , 415.Xr syslog 3 , 416.Xr syslogd 8 417