Annotation of src/usr.bin/newsyslog/newsyslog.8, Revision 1.46
1.46 ! lum 1: .\" $OpenBSD: newsyslog.8,v 1.45 2009/11/28 14:42:04 schwarze Exp $
1.4 downsj 2: .\"
3: .\" Copyright (c) 1997, Jason Downs. All rights reserved.
4: .\"
5: .\" Redistribution and use in source and binary forms, with or without
6: .\" modification, are permitted provided that the following conditions
7: .\" are met:
8: .\" 1. Redistributions of source code must retain the above copyright
9: .\" notice, this list of conditions and the following disclaimer.
10: .\" 2. Redistributions in binary form must reproduce the above copyright
11: .\" notice, this list of conditions and the following disclaimer in the
12: .\" documentation and/or other materials provided with the distribution.
13: .\"
14: .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
15: .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16: .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17: .\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
18: .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19: .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20: .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21: .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24: .\" SUCH DAMAGE.
25: .\"
1.1 deraadt 26: .\" This file contains changes from the Open Software Foundation.
27: .\"
28: .\" from: @(#)newsyslog.8
29: .\"
30: .\" Copyright 1988, 1989 by the Massachusetts Institute of Technology
1.13 aaron 31: .\"
1.1 deraadt 32: .\" Permission to use, copy, modify, and distribute this software
33: .\" and its documentation for any purpose and without fee is
34: .\" hereby granted, provided that the above copyright notice
35: .\" appear in all copies and that both that copyright notice and
36: .\" this permission notice appear in supporting documentation,
37: .\" and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
38: .\" used in advertising or publicity pertaining to distribution
39: .\" of the software without specific, written prior permission.
40: .\" M.I.T. and the M.I.T. S.I.P.B. make no representations about
41: .\" the suitability of this software for any purpose. It is
42: .\" provided "as is" without express or implied warranty.
43: .\"
1.46 ! lum 44: .Dd $Mdocdate: November 28 2009 $
1.4 downsj 45: .Dt NEWSYSLOG 8
1.12 aaron 46: .Os
1.4 downsj 47: .Sh NAME
48: .Nm newsyslog
1.45 schwarze 49: .Nd rotate log files
1.4 downsj 50: .Sh SYNOPSIS
1.10 aaron 51: .Nm newsyslog
1.27 millert 52: .Op Fl Fmnrv
1.26 millert 53: .Op Fl a Ar directory
1.20 aaron 54: .Op Fl f Ar config_file
1.28 millert 55: .Op Ar log ...
1.4 downsj 56: .Sh DESCRIPTION
1.45 schwarze 57: The
1.13 aaron 58: .Nm
1.45 schwarze 59: utility rotates log files when they exceed a configurable size or age.
60: The
61: .Ar log
62: file is renamed to
63: .Pa log.0
64: and an empty file is created in its place.
65: An archive of older logs may be kept:
66: in order of increasing age, these files are named
67: .Pa log.1 ,
68: .Pa log.2 ,
69: and so on.
70: When their number exceeds a given limit, the oldest is removed.
71: The archived logs may also be compressed.
1.4 downsj 72: .Pp
1.18 aaron 73: The options are as follows:
74: .Bl -tag -width Ds
1.40 jmc 75: .It Fl a Ar directory
76: Specify a
77: .Ar directory
78: into which archived log files will be written.
79: If
80: .Ar directory
81: is a relative path, it is appended to the parent directory
82: of each log and the archived log is stored in the result.
83: If an absolute path is given, all archived logs are stored in the given
84: .Ar directory .
85: If
86: .Ar directory
87: does not exist for a specified log, it is ignored for that entry and
88: the log is rotated as if the
89: .Fl a
90: option was not specified.
1.27 millert 91: .It Fl F
92: Force
93: .Nm
94: to trim logs regardless of the size and/or age requirements specified in
95: .Pa /etc/newsyslog.conf .
96: This option may be combined with the
97: .Fl n
98: or
99: .Fl v
100: flags to aid in debugging problems with
101: .Pa /etc/newsyslog.conf .
1.40 jmc 102: .It Fl f Ar config_file
103: Use
104: .Ar config_file
105: instead of
106: .Pa /etc/newsyslog.conf
107: for the configuration file.
1.20 aaron 108: .It Fl m
109: Monitoring mode; only entries marked with an
110: .Sq M
1.31 millert 111: in flags are processed.
1.36 jmc 112: For each log file being monitored, any log output since the last time
1.31 millert 113: .Nm
114: was run with the
115: .Fl m
116: flag is mailed to the user listed in the monitor notification section.
1.18 aaron 117: .It Fl n
118: Do not trim the logs, but instead print out what would be done if this option
119: were not specified.
120: .It Fl r
121: Removes the restriction that
122: .Nm
123: must be running as root.
1.34 millert 124: Note that in this mode
1.18 aaron 125: .Nm
126: will not be able to send a
127: .Dv SIGHUP
128: signal to
1.34 millert 129: .Xr syslogd 8 .
1.20 aaron 130: .It Fl v
1.33 millert 131: Place
132: .Nm newsyslog
133: in verbose mode.
1.20 aaron 134: In this mode it will print out each log and its
135: reasons for either trimming that log or skipping it.
1.18 aaron 136: .El
1.28 millert 137: .Pp
1.45 schwarze 138: In the default system configuration,
139: .Nm
140: is run by
141: .Xr cron 8 ,
142: but it may also be run manually.
1.28 millert 143: If one or more
144: .Ar log
1.45 schwarze 145: files are specified on the command line, only the specified files are
146: rotated.
1.28 millert 147: Note that each
148: .Ar log
149: specified must have an entry in
150: .Pa /etc/newsyslog.conf .
1.18 aaron 151: .Pp
1.32 jmc 152: A log can be archived because of two reasons:
1.18 aaron 153: The log file can have
1.1 deraadt 154: grown bigger than a preset size in kilobytes, or a preset number of
1.18 aaron 155: hours may have elapsed since the last log archive.
156: The granularity of
1.13 aaron 157: .Nm
1.4 downsj 158: is dependent on how often it is scheduled to run in
159: .Xr cron 8 .
160: Since the program is quite fast, it may be scheduled to run every hour
1.1 deraadt 161: without any ill effects.
1.4 downsj 162: .Pp
1.13 aaron 163: When starting up,
164: .Nm
1.1 deraadt 165: reads in a configuration file to determine which logs should be looked
1.18 aaron 166: at.
167: By default, this configuration file is
1.4 downsj 168: .Pa /etc/newsyslog.conf .
1.1 deraadt 169: Each line of the file contains information about a particular log file
170: that should be handled by
1.4 downsj 171: .Nm newsyslog .
1.34 millert 172: Each line has five mandatory fields and up to three optional fields, with
1.18 aaron 173: whitespace separating each field.
174: Blank lines or lines beginning with a hash mark
175: .Pq Ql #
176: are ignored.
177: The fields of the configuration file are as
1.13 aaron 178: follows:
1.4 downsj 179: .Bl -tag -width XXXXXXXXXXXXXXXX
1.33 millert 180: .It Ar logfile_name
1.4 downsj 181: The full pathname of the system log file to be archived.
1.33 millert 182: .It Ar owner:group
183: This optional field specifies the owner and group for the archive file.
1.18 aaron 184: The
1.34 millert 185: .Ql \&:
1.13 aaron 186: is essential, even if the
1.4 downsj 187: .Ar owner
1.1 deraadt 188: or
1.4 downsj 189: .Ar group
1.18 aaron 190: field is left blank.
191: The fields may be numeric, or a name which is looked up
1.4 downsj 192: in the system password and group databases.
1.33 millert 193: For backwards compatibility, a
194: .Ql \&.
195: may be used instead of a
1.34 millert 196: .Ql \&: .
1.38 millert 197: If either
198: .Ar owner
199: or
200: .Ar group
201: is not specified, the owner and/or group of the existing log file is used.
1.33 millert 202: .It Ar mode
203: File mode (in octal) to use for created log files and archives.
204: .It Ar count
205: The number of archives to be kept besides the log file itself.
206: .It Ar size
1.24 millert 207: When the size of the log file (in kilobytes) reaches this point, the log
208: file is trimmed as described above.
1.33 millert 209: If this field is replaced by an
1.42 jmc 210: .Ql * ,
211: or set to
212: .Ql 0 ,
1.13 aaron 213: then the size of
1.4 downsj 214: the log file is not taken into account when determining when to trim the
215: log file.
1.46 ! lum 216: By default, files smaller than 256 bytes are not rotated unless the
1.24 millert 217: .Sq B
1.42 jmc 218: (binary) flag is set or the
219: .Fl F
220: option is specified.
1.24 millert 221: This prevents
222: .Nm
223: from rotating files consisting solely of a message indicating
224: that the log file has been turned over.
1.33 millert 225: .It Ar when
1.1 deraadt 226: The
1.33 millert 227: .Ar when
228: field can consist of an interval, a specific time, or both.
229: If the
230: .Ar when
231: field consists of an asterisk
232: .Pq Ql \&* ,
233: log rotation will depend only on the contents of the
234: .Ar size
235: field.
236: Otherwise, the
237: .Ar when
238: field consists of an optional interval in hours, possibly followed
239: by an
1.37 jmc 240: .So Li \&@ Sc Ns -sign
1.33 millert 241: and a time in a restricted
242: .Tn ISO 8601
243: format or by a
1.37 jmc 244: .So Li \&$ Sc Ns -sign
1.33 millert 245: and a time specification for logfile rotation at a fixed time once
246: per day, per week or per month.
247: .Pp
248: If a time is specified, the log file will only be trimmed if
249: .Nm
250: is run within one hour of the specified time.
251: If an interval is specified, the log file will be trimmed if that
252: many hours have passed since the last rotation.
253: When both a time and an interval are specified, both conditions
254: must be satisfied for the rotation to take place.
255: .Pp
1.41 jmc 256: There is no provision for the specification of a time zone.
1.33 millert 257: There is little point in specifying an explicit minutes or seconds
258: component in the current implementation, since the only comparison is
259: .Sq within the hour .
1.39 jmc 260: .Pp
261: .Sy ISO 8601 restricted time format:
1.33 millert 262: The lead-in character for a restricted
263: .Tn ISO 8601
264: time is an
1.37 jmc 265: .So Li \&@ Sc Ns -sign .
1.33 millert 266: The particular format of the time in restricted
267: .Tn ISO 8601
268: is:
269: .Sm off
270: .Oo Oo Oo Oo Oo
271: .Va \&cc Oc
272: .Va \&yy Oc
273: .Va \&mm Oc
274: .Va \&dd Oc
275: .Oo Li \&T
276: .Oo Va \&hh
277: .Oo Va \&mm
278: .Oo Va \&ss
279: .Oc Oc Oc Oc Oc .
280: .Sm on
281: Optional date fields default to the appropriate component of the
1.43 jmc 282: current date; optional time fields default to midnight.
1.33 millert 283: For example, if today is January 22, 1999, the following date specifications
284: are all equivalent:
285: .Pp
286: .Bl -item -compact -offset indent
287: .It
288: .Ql 19990122T000000
289: .It
290: .Ql 990122T000000
291: .It
292: .Ql 0122T000000
293: .It
294: .Ql 22T000000
295: .It
296: .Ql T000000
297: .It
298: .Ql T0000
299: .It
300: .Ql T00
301: .It
302: .Ql 22T
303: .It
304: .Ql \&T
305: .It
306: .Ql \&
307: .El
1.39 jmc 308: .Pp
309: .Sy Day, week and month time format:
1.33 millert 310: The lead-in character for day, week and month specification is a
1.37 jmc 311: .So Li \&$ Sc Ns -sign .
1.33 millert 312: The particular format of day, week and month specification is:
313: .Op Va D\&hh ,
314: .Op Va W\&w Ns Op Va D\&hh
315: and
316: .Op Va M\&dd Ns Op Va D\&hh ,
317: respectively.
318: Optional time fields default to midnight.
319: The ranges for day and hour specifications are:
320: .Pp
321: .Bl -tag -width Ds -compact -offset indent
322: .It Ar hh
323: hours, range 0 ... 23
324: .It Ar w
325: day of week, range 0 ... 6, 0 = Sunday
326: .It Ar dd
327: day of month, range 1 ... 31, or the letter
328: .Em L
329: or
330: .Em l
331: to specify the last day of the month.
332: .El
1.39 jmc 333: .Pp
334: .Sy Some examples:
1.33 millert 335: .Bl -tag -width Ds -compact -offset indent
336: .It Ar $D0
337: rotate every night at midnight
338: (same as
339: .Ar @T00 )
340: .It Ar $D23
341: rotate every day at 23:00 hr
342: (same as
343: .Ar @T23 )
344: .It Ar $W0D23
345: rotate every week on Sunday at 23:00 hr
346: .It Ar $W5D16
347: rotate every week on Friday at 16:00 hr
348: .It Ar $M1D0
349: rotate on the first day of every month at midnight
350: (i.e., the start of the day; same as
351: .Ar @01T00 )
352: .It Ar $M5D6
353: rotate on every 5th day of the month at 6:00 hr
354: (same as
355: .Ar @05T06 )
356: .El
357: .Pp
358: .It Ar flags
359: The optional
1.4 downsj 360: .Ar flags
1.1 deraadt 361: field specifies if the archives should have any special processing
1.18 aaron 362: done to the archived log files.
363: The
1.13 aaron 364: .Sq Z
365: flag will make the archive
1.4 downsj 366: files compressed to save space using
367: .Xr gzip 1
368: or
369: .Xr compress 1 ,
1.18 aaron 370: depending on compilation options.
371: The
1.13 aaron 372: .Sq B
373: flag means that the file is a
1.8 aaron 374: binary file, and so the ASCII message which
1.13 aaron 375: .Nm
1.1 deraadt 376: inserts to indicate the fact that the logs have been turned over
1.18 aaron 377: should not be included.
378: The
1.13 aaron 379: .Sq M
380: flag marks this entry as a monitored
1.4 downsj 381: log file.
1.22 wcobb 382: The
383: .Sq F
384: flag specifies that symbolic links should be followed.
1.33 millert 385: .It Ar monitor
1.31 millert 386: Specify the username (or email address) that should receive notification
387: messages if this is a monitored log file.
1.18 aaron 388: Notification messages are sent as email; the operator
1.13 aaron 389: deserves what they get if they mark the
1.5 downsj 390: .Xr sendmail 8
1.6 d 391: log file as monitored.
1.33 millert 392: This field is only valid when the
393: .Sq M
394: flag is set.
395: .It Ar pid_file
396: This optional field specifies a file containing the PID of a process to send a
397: signal (usually
398: .Dv SIGHUP )
399: to instead of
1.7 millert 400: .Pa /var/run/syslog.pid .
1.33 millert 401: .It Ar signal
1.18 aaron 402: Specify the signal to send to the process instead of
403: .Dv SIGHUP .
404: Signal names
1.16 millert 405: must start with
406: .Dq SIG
1.18 aaron 407: and be the signal name, not the number, e.g.,
1.23 millert 408: .Dv SIGUSR1 .
1.33 millert 409: .It Ar command
410: This optional field specifies a command to run instead of sending a signal
411: to the process.
1.18 aaron 412: The command must be enclosed in double quotes
1.30 deraadt 413: .Pq Ql \&" .
1.29 millert 414: The empty string,
415: .Ql \&"\&" ,
1.42 jmc 416: can be used to prevent
1.29 millert 417: .Nm
418: from sending a signal or running a command.
1.18 aaron 419: You cannot specify both a command and a PID file.
1.25 millert 420: .Em NOTE:
1.19 millert 421: If you specify a command to be run,
422: .Nm
423: will not send a
424: .Dv SIGHUP to
425: .Xr syslogd 8 .
1.4 downsj 426: .El
427: .Sh FILES
428: .Bl -tag -width /etc/newsyslog.conf
429: .It Pa /etc/newsyslog.conf
1.11 aaron 430: default configuration file
1.4 downsj 431: .El
432: .Sh SEE ALSO
1.8 aaron 433: .Xr compress 1 ,
1.4 downsj 434: .Xr gzip 1 ,
435: .Xr syslog 3 ,
1.8 aaron 436: .Xr syslogd 8
1.21 mpech 437: .Sh AUTHORS
1.18 aaron 438: .Bd -unfilled
1.1 deraadt 439: Theodore Ts'o, MIT Project Athena
440: Copyright 1987, Massachusetts Institute of Technology
1.4 downsj 441: .Ed