Annotation of src/usr.bin/newsyslog/newsyslog.8, Revision 1.36
1.36 ! jmc 1: .\" $OpenBSD: newsyslog.8,v 1.35 2003/06/03 21:09:02 deraadt 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.31 millert 44: .Dd January 24, 2003
1.4 downsj 45: .Dt NEWSYSLOG 8
1.12 aaron 46: .Os
1.4 downsj 47: .Sh NAME
48: .Nm newsyslog
1.34 millert 49: .Nd trim log files to manageable sizes
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.13 aaron 57: .Nm
1.1 deraadt 58: is a program that should be scheduled to run periodically by
1.4 downsj 59: .Xr cron 8 .
1.18 aaron 60: When it is executed it archives log files if necessary.
61: If a log file is determined to require archiving,
1.13 aaron 62: .Nm
63: rearranges the files so that
64: .Pa logfile
65: is empty,
66: .Pa logfile.0
67: has
68: the last period's logs in it,
69: .Pa logfile.1
70: has the next to last
1.1 deraadt 71: period's logs in it, and so on, up to a user-specified number of
1.18 aaron 72: archived logs.
1.33 millert 73: The archived logs may be optionally compressed to save space.
1.4 downsj 74: .Pp
1.18 aaron 75: The options are as follows:
76: .Bl -tag -width Ds
1.27 millert 77: .It Fl F
78: Force
79: .Nm
80: to trim logs regardless of the size and/or age requirements specified in
81: .Pa /etc/newsyslog.conf .
82: This option may be combined with the
83: .Fl n
84: or
85: .Fl v
86: flags to aid in debugging problems with
87: .Pa /etc/newsyslog.conf .
1.20 aaron 88: .It Fl m
89: Monitoring mode; only entries marked with an
90: .Sq M
1.31 millert 91: in flags are processed.
1.36 ! jmc 92: For each log file being monitored, any log output since the last time
1.31 millert 93: .Nm
94: was run with the
95: .Fl m
96: flag is mailed to the user listed in the monitor notification section.
1.18 aaron 97: .It Fl n
98: Do not trim the logs, but instead print out what would be done if this option
99: were not specified.
100: .It Fl r
101: Removes the restriction that
102: .Nm
103: must be running as root.
1.34 millert 104: Note that in this mode
1.18 aaron 105: .Nm
106: will not be able to send a
107: .Dv SIGHUP
108: signal to
1.34 millert 109: .Xr syslogd 8 .
1.20 aaron 110: .It Fl v
1.33 millert 111: Place
112: .Nm newsyslog
113: in verbose mode.
1.20 aaron 114: In this mode it will print out each log and its
115: reasons for either trimming that log or skipping it.
1.26 millert 116: .It Fl a Ar directory
117: Specify a
118: .Ar directory
119: into which archived log files will be written.
120: If
121: .Ar directory
1.32 jmc 122: is a relative path, it is appended to the parent directory
1.26 millert 123: of each log and the archived log is stored in the result.
124: If an absolute path is given, all archived logs are stored in the given
125: .Ar directory .
126: If
127: .Ar directory
128: does not exist for a specified log, it is ignored for that entry and
129: the log is rotated as if the
130: .Fl a
131: option was not specified.
1.20 aaron 132: .It Fl f Ar config_file
133: Use
134: .Ar config_file
135: instead of
136: .Pa /etc/newsyslog.conf
137: for the configuration file.
1.18 aaron 138: .El
1.28 millert 139: .Pp
140: If one or more
141: .Ar log
142: files are specified on the command line, only the specified logs will
143: be rotated.
144: Note that each
145: .Ar log
146: specified must have an entry in
147: .Pa /etc/newsyslog.conf .
1.18 aaron 148: .Pp
1.32 jmc 149: A log can be archived because of two reasons:
1.18 aaron 150: The log file can have
1.1 deraadt 151: grown bigger than a preset size in kilobytes, or a preset number of
1.18 aaron 152: hours may have elapsed since the last log archive.
153: The granularity of
1.13 aaron 154: .Nm
1.4 downsj 155: is dependent on how often it is scheduled to run in
156: .Xr cron 8 .
157: Since the program is quite fast, it may be scheduled to run every hour
1.1 deraadt 158: without any ill effects.
1.4 downsj 159: .Pp
1.13 aaron 160: When starting up,
161: .Nm
1.1 deraadt 162: reads in a configuration file to determine which logs should be looked
1.18 aaron 163: at.
164: By default, this configuration file is
1.4 downsj 165: .Pa /etc/newsyslog.conf .
1.1 deraadt 166: Each line of the file contains information about a particular log file
167: that should be handled by
1.4 downsj 168: .Nm newsyslog .
1.34 millert 169: Each line has five mandatory fields and up to three optional fields, with
1.18 aaron 170: whitespace separating each field.
171: Blank lines or lines beginning with a hash mark
172: .Pq Ql #
173: are ignored.
174: The fields of the configuration file are as
1.13 aaron 175: follows:
1.4 downsj 176: .Bl -tag -width XXXXXXXXXXXXXXXX
1.33 millert 177: .It Ar logfile_name
1.4 downsj 178: The full pathname of the system log file to be archived.
1.33 millert 179: .It Ar owner:group
180: This optional field specifies the owner and group for the archive file.
1.18 aaron 181: The
1.34 millert 182: .Ql \&:
1.13 aaron 183: is essential, even if the
1.4 downsj 184: .Ar owner
1.1 deraadt 185: or
1.4 downsj 186: .Ar group
1.18 aaron 187: field is left blank.
188: The fields may be numeric, or a name which is looked up
1.4 downsj 189: in the system password and group databases.
1.33 millert 190: For backwards compatibility, a
191: .Ql \&.
192: may be used instead of a
1.34 millert 193: .Ql \&: .
1.33 millert 194: .It Ar mode
195: File mode (in octal) to use for created log files and archives.
196: .It Ar count
197: The number of archives to be kept besides the log file itself.
198: .It Ar size
1.24 millert 199: When the size of the log file (in kilobytes) reaches this point, the log
200: file is trimmed as described above.
1.33 millert 201: If this field is replaced by an
202: .Ql \&* ,
1.13 aaron 203: then the size of
1.4 downsj 204: the log file is not taken into account when determining when to trim the
205: log file.
1.25 millert 206: By default, files smaller than 512 bytes are not rotated unless the
1.24 millert 207: .Sq B
208: (binary) flag is set.
209: This prevents
210: .Nm
211: from rotating files consisting solely of a message indicating
212: that the log file has been turned over.
1.33 millert 213: .It Ar when
1.1 deraadt 214: The
1.33 millert 215: .Ar when
216: field can consist of an interval, a specific time, or both.
217: If the
218: .Ar when
219: field consists of an asterisk
220: .Pq Ql \&* ,
221: log rotation will depend only on the contents of the
222: .Ar size
223: field.
224: Otherwise, the
225: .Ar when
226: field consists of an optional interval in hours, possibly followed
227: by an
228: .So Li \&@ Sc Ns No -sign
229: and a time in a restricted
230: .Tn ISO 8601
231: format or by a
232: .So Li \&$ Sc Ns No -sign
233: and a time specification for logfile rotation at a fixed time once
234: per day, per week or per month.
235: .Pp
236: If a time is specified, the log file will only be trimmed if
237: .Nm
238: is run within one hour of the specified time.
239: If an interval is specified, the log file will be trimmed if that
240: many hours have passed since the last rotation.
241: When both a time and an interval are specified, both conditions
242: must be satisfied for the rotation to take place.
243: .Pp
244: There is no provision for the specification of a timezone.
245: There is little point in specifying an explicit minutes or seconds
246: component in the current implementation, since the only comparison is
247: .Sq within the hour .
248: .Ss ISO 8601 restricted time format
249: The lead-in character for a restricted
250: .Tn ISO 8601
251: time is an
252: .So Li \&@ Sc Ns No -sign .
253: The particular format of the time in restricted
254: .Tn ISO 8601
255: is:
256: .Sm off
257: .Oo Oo Oo Oo Oo
258: .Va \&cc Oc
259: .Va \&yy Oc
260: .Va \&mm Oc
261: .Va \&dd Oc
262: .Oo Li \&T
263: .Oo Va \&hh
264: .Oo Va \&mm
265: .Oo Va \&ss
266: .Oc Oc Oc Oc Oc .
267: .Sm on
268: Optional date fields default to the appropriate component of the
269: current date; optional time fields default to midnight
270: For example, if today is January 22, 1999, the following date specifications
271: are all equivalent:
272: .Pp
273: .Bl -item -compact -offset indent
274: .It
275: .Ql 19990122T000000
276: .It
277: .Ql 990122T000000
278: .It
279: .Ql 0122T000000
280: .It
281: .Ql 22T000000
282: .It
283: .Ql T000000
284: .It
285: .Ql T0000
286: .It
287: .Ql T00
288: .It
289: .Ql 22T
290: .It
291: .Ql \&T
292: .It
293: .Ql \&
294: .El
295: .Ss Day, week and month time format
296: The lead-in character for day, week and month specification is a
297: .So Li \&$ Sc Ns No -sign .
298: The particular format of day, week and month specification is:
299: .Op Va D\&hh ,
300: .Op Va W\&w Ns Op Va D\&hh
301: and
302: .Op Va M\&dd Ns Op Va D\&hh ,
303: respectively.
304: Optional time fields default to midnight.
305: The ranges for day and hour specifications are:
306: .Pp
307: .Bl -tag -width Ds -compact -offset indent
308: .It Ar hh
309: hours, range 0 ... 23
310: .It Ar w
311: day of week, range 0 ... 6, 0 = Sunday
312: .It Ar dd
313: day of month, range 1 ... 31, or the letter
314: .Em L
315: or
316: .Em l
317: to specify the last day of the month.
318: .El
319: .Ss Some examples:
320: .Bl -tag -width Ds -compact -offset indent
321: .It Ar $D0
322: rotate every night at midnight
323: (same as
324: .Ar @T00 )
325: .It Ar $D23
326: rotate every day at 23:00 hr
327: (same as
328: .Ar @T23 )
329: .It Ar $W0D23
330: rotate every week on Sunday at 23:00 hr
331: .It Ar $W5D16
332: rotate every week on Friday at 16:00 hr
333: .It Ar $M1D0
334: rotate on the first day of every month at midnight
335: (i.e., the start of the day; same as
336: .Ar @01T00 )
337: .It Ar $M5D6
338: rotate on every 5th day of the month at 6:00 hr
339: (same as
340: .Ar @05T06 )
341: .El
342: .Pp
343: .It Ar flags
344: The optional
1.4 downsj 345: .Ar flags
1.1 deraadt 346: field specifies if the archives should have any special processing
1.18 aaron 347: done to the archived log files.
348: The
1.13 aaron 349: .Sq Z
350: flag will make the archive
1.4 downsj 351: files compressed to save space using
352: .Xr gzip 1
353: or
354: .Xr compress 1 ,
1.18 aaron 355: depending on compilation options.
356: The
1.13 aaron 357: .Sq B
358: flag means that the file is a
1.8 aaron 359: binary file, and so the ASCII message which
1.13 aaron 360: .Nm
1.1 deraadt 361: inserts to indicate the fact that the logs have been turned over
1.18 aaron 362: should not be included.
363: The
1.13 aaron 364: .Sq M
365: flag marks this entry as a monitored
1.4 downsj 366: log file.
1.22 wcobb 367: The
368: .Sq F
369: flag specifies that symbolic links should be followed.
1.33 millert 370: .It Ar monitor
1.31 millert 371: Specify the username (or email address) that should receive notification
372: messages if this is a monitored log file.
1.18 aaron 373: Notification messages are sent as email; the operator
1.13 aaron 374: deserves what they get if they mark the
1.5 downsj 375: .Xr sendmail 8
1.6 d 376: log file as monitored.
1.33 millert 377: This field is only valid when the
378: .Sq M
379: flag is set.
380: .It Ar pid_file
381: This optional field specifies a file containing the PID of a process to send a
382: signal (usually
383: .Dv SIGHUP )
384: to instead of
1.7 millert 385: .Pa /var/run/syslog.pid .
1.33 millert 386: .It Ar signal
1.18 aaron 387: Specify the signal to send to the process instead of
388: .Dv SIGHUP .
389: Signal names
1.16 millert 390: must start with
391: .Dq SIG
1.18 aaron 392: and be the signal name, not the number, e.g.,
1.23 millert 393: .Dv SIGUSR1 .
1.33 millert 394: .It Ar command
395: This optional field specifies a command to run instead of sending a signal
396: to the process.
1.18 aaron 397: The command must be enclosed in double quotes
1.30 deraadt 398: .Pq Ql \&" .
1.29 millert 399: The empty string,
400: .Ql \&"\&" ,
401: can use used to prevent
402: .Nm
403: from sending a signal or running a command.
1.18 aaron 404: You cannot specify both a command and a PID file.
1.25 millert 405: .Em NOTE:
1.19 millert 406: If you specify a command to be run,
407: .Nm
408: will not send a
409: .Dv SIGHUP to
410: .Xr syslogd 8 .
1.4 downsj 411: .El
412: .Sh FILES
413: .Bl -tag -width /etc/newsyslog.conf
414: .It Pa /etc/newsyslog.conf
1.11 aaron 415: default configuration file
1.4 downsj 416: .El
417: .Sh SEE ALSO
1.8 aaron 418: .Xr compress 1 ,
1.4 downsj 419: .Xr gzip 1 ,
420: .Xr syslog 3 ,
1.8 aaron 421: .Xr syslogd 8
1.21 mpech 422: .Sh AUTHORS
1.18 aaron 423: .Bd -unfilled
1.1 deraadt 424: Theodore Ts'o, MIT Project Athena
425: Copyright 1987, Massachusetts Institute of Technology
1.4 downsj 426: .Ed