2 .\" Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH LOGADM 1M "May 23, 2007"
8 logadm \- manage endlessly growing log files
17 \fBlogadm\fR [\fB-\fIoptions\fR\fR] \fIlogname\fR...
23 \fBlogadm\fR is a general log rotation tool that is suitable for running from
27 Without arguments, \fBlogadm\fR reads the \fB/etc/logadm.conf\fR file, and for
28 every entry found in that file checks the corresponding log file to see if it
29 should be rotated. Typically this check is done each morning by an entry in the
33 If the \fIlogname\fR argument is specified, \fBlogadm\fR renames the
34 corresponding log file by adding a suffix so that the most recent log file ends
35 with \fB\&.0\fR (that is, \fIlogfile\fR\fB\&.0\fR), the next most recent ends
36 with \fB\&.1\fR (that is, \fIlogfile\fR\fB\&.1\fR), and so forth. By default,
37 ten versions of old log files are kept (that is, \fIlogfile\fR\fB\&.0\fR
38 through \fIlogfile\fR\fB\&.9\fR). At the point when what would be the eleventh
39 file is logged, \fBlogadm\fR automatically deletes the oldest version to keep
40 the count of files at ten.
43 \fBlogadm\fR takes a number of \fIoptions\fR. You can specify these options on
44 the command line or in the \fB/etc/logadm.conf\fR file. The \fBlogadm\fR
45 command searches \fB/etc/logadm.conf\fR for lines of the form \fIlogname\fR
54 Identifies an entry in \fB/etc/logadm.conf\fR. This can be a name or the
55 pathname of the log file. If you specify a log file, rather than a name, for
56 this field, it must be a fully qualified pathname.
66 Identifies command line options exactly as they would be entered on the command
67 line. This allows commonly used log rotation policies to be stored in the
68 \fB/etc/logadm.conf\fR file. See \fBEXAMPLES\fR.
70 If \fIoptions\fR are specified both in \fB/etc/logadm.conf\fR and on the
71 command line, those in the \fB/etc/logadm.conf\fR file are applied first.
72 Therefore, the command line options override those in \fB/etc/logadm.conf\fR.
74 Log file names specified in \fB/etc/logadm.conf\fR may contain filename
75 substitution characters such as \fB*\fR and \fB?\fR, that are supported by
81 Two options control when a log file is rotated. They are: \fB-s\fR size
85 When using more than one of these options at a time, there is an implied
86 \fBand\fR between them. This means that all conditions must be met before the
90 If neither of these two options are specified, the default conditions for
91 rotating a log file are: \fB\fR\fB-s\fR \fB1b\fR \fB-p\fR \fB1w\fR, which means
92 the log file is only rotated if the size is non-zero and if at least 1 week has
93 passed since the last time it was rotated.
96 By specifying \fB\fR\fB-p\fR \fBnever\fR as a rotation condition, any other
97 rotation conditions are ignored and \fBlogadm\fR moves on to the expiration of
98 old log files. By specifying \fB\fR\fB-p\fR \fBnow\fR as a rotation condition,
99 a log rotation is forced.
102 Unless specified by the \fB-o\fR, \fB-g\fR, or \fB-m\fR options, \fBlogadm\fR
103 replaces the log file (after renaming it) by creating an empty file whose
104 owner, group ID, and permissions match the original file.
107 Three options control when old log files are expired: \fB-A\fR age \fB-C\fR
108 count \fB-S\fR size. These options expire the oldest log files until a
109 particular condition or conditions are met. For example, the combination
110 \fB\fR\fB-C\fR \fB5\fR and the \fB\fR\fB-S\fR \fB10m\fR options expires old log
111 files until there are no more than 5 of the \fBand\fR their combined disk usage
112 is no more than 10 megabytes. If none of these options are specified, the
113 default expiration is \fB\fR\fB-C\fR \fB10\fR which keeps ten old log files. If
114 no files are to be expired, use \fB\fR\fB-C\fR \fB0\fR to prevent expiration by
119 The following options are supported:
123 \fB\fB-a\fR \fIpost_command\fR\fR
127 Execute the \fIpost_command\fR after renaming the log file. \fIpost_command\fR
128 is passed to \fBsh\fR \fB-c\fR.
130 Specify \fIpost_command\fR as a valid shell command. Use quotes to protect
131 spaces or shell metacharacters in \fIpost_command\fR.
133 This option can be used to restart a daemon that is writing to the file. When
134 rotating multiple logs with one \fBlogadm\fR command, \fIpost_command\fR is
135 executed only once after all the logs are rotated, not once per rotated log.
141 \fB\fB-A\fR \fIage\fR\fR
145 Delete any versions that have not been modified for the amount of time
146 specified by \fIage\fR.
148 Specify \fIage\fR as a number followed by an \fBh\fR (hours), \fBd\fR (days),
149 \fBw\fR(weeks), \fBm\fR (months), or \fBy\fR (years).
155 \fB\fB-b\fR \fIpre_command\fR\fR
159 Execute \fIpre_command\fR before renaming the log file. \fIpre_command\fR is
160 passed to \fBsh\fR \fB-c\fR.
162 Specify \fIpre_command\fR as a valid shell command. Use quotes to protect
163 spaces or shell metacharacters in the \fIpre_command\fR.
165 This option can be used to stop a daemon that is writing to the file. When
166 rotating multiple logs with one \fBlogadm\fR command, \fIpre_command\fR is
167 executed only once before all the logs are rotated, not once per rotated log.
177 Rotate the log file by copying it and truncating the original logfile to zero
178 length, rather than renaming the file.
184 \fB\fB-C\fR \fIcount\fR\fR
188 Delete the oldest versions until there are not more than \fIcount\fR files
191 If no expire options (\fB-A\fR, \fB-C\fR, or \fB-S\fR) are specified,
192 \fB\fR\fB-C\fR \fB10\fR is the default. To prevent the default expire rule from
193 being added automatically, specify \fB\fR\fB-C\fR \fB0\fR .
199 \fB\fB-e\fR \fImail_addr\fR\fR
203 Send error messages by email to \fImail_addr\fR.
205 As \fBlogadm\fR is typically run from \fBcron\fR(1M), error messages are
206 captured by \fBcron\fR and mailed to the owner of the \fBcrontab\fR.
208 This option is useful if you want the mail regarding error messages to go to
209 another address instead. If no errors are encountered, no mail message is
216 \fB\fB-E\fR \fIcmd\fR\fR
220 Execute \fIcmd\fR to expire the file, rather than deleting the old log file to
223 \fIcmd\fR is passed it to \fBsh\fR \fB-c\fR. The file is considered expired
224 after \fIcmd\fR completes. If the old log file is not removed or renamed by the
225 \fIcmd\fR, \fBlogadm\fR considers it for expiration the next time that it runs
226 on the specified log file. If present, the keyword \fB$file\fR is expanded in
227 the specified \fIcmd\fRto the name of the file being expired.
229 This option is useful for tasks such as mailing old log files to
230 administrators, or copying old log files to long term storage.
236 \fB\fB-f\fR \fIconf_file\fR\fR
240 Use \fIconf_file\fR instead of \fB/etc/logadm.conf\fR.
242 This option allows non-root users to keep their own \fBlogadm\fR configuration
249 \fB\fB-g\fR \fIgroup\fR\fR
253 Create a new empty file with the \fBID\fR specified by \fIgroup\fR, instead of
254 preserving the group \fBID\fR of the log file.
256 Specify \fIgroup\fR by name or by numeric group \fBID\fR, as accepted by
259 This option requires the ability to change file group ownership using the
260 \fBchgrp\fR(1) command.
270 Print a help message that describes \fBlogadm\fR's options.
280 Use local time rather than the Coordinated Universal Time (UTC) when naming
281 rotated log files (see the discussion of percent sequences in the templates
282 supplied with the \fB-t\fR option).
288 \fB\fB-m\fR \fImode\fR\fR
292 Create a new empty file with the mode specified by \fImode\fR, instead of
293 preserving the mode of the log file.
295 Specify \fImode\fR in any form that is accepted by the \fBchmod\fR(1) command.
301 \fB\fB-M\fR \fIcmd\fR\fR
305 Use \fIcmd\fR to rename the log file. If the keyword \fB$file\fR is specified,
306 it is expanded to the name of the log file. Similarly, the keyword \fB$nfile\fR
307 is expanded to the new name of the log file. The \fB$nfile\fR keyword is only
308 available with commands provided with the \fB-M\fR option. After the command
309 completes, the log file is replaced by the rotate file. The default \fIcmd\fR
310 is "\fB/bin/mv\fR \fB$file\fR\fB\fR\fB$nfile\fR".
316 \fB\fB-n\fR \fI\fR\fR
320 Print the actions that the \fBlogadm\fR command will perform without actually
323 This option is useful for checking arguments before making any changes to the
326 It is important to remember, however, that since log rotating actions are only
327 printed with this option, \fBlogadm\fR might not find files that need expiring,
328 but if run without the \fB-n\fR \fBlogadm\fR might create a file that needs
329 expiring by performing the log rotating actions. Therefore, if you see no files
330 being expired with the \fB-n\fR option, files still might be expired without
341 Prevent an error message if the specified logfile does not exist. Normally,
342 \fBlogadm\fR produces an error message if the log file is not found. With
343 \fB-N\fR, if the log file doesn't exist \fBlogadm\fR moves on to the expire
344 rules (if any) and then to the next log file (if any), without creating the
345 empty replacement log file.
351 \fB\fB-o\fR \fIowner\fR\fR
355 Create the new empty file with \fIowner\fR, instead of preserving the owner of
358 Specify \fIowner\fR in any form that is accepted by the \fBchown\fR(1) command.
364 \fB\fB-p\fR \fIperiod\fR\fR
368 Rotate a log file after the specified time period (\fIperiod\fR).
370 Specify \fIperiod\fR as a number followed by \fBd\fR for days, \fBh\fR for
371 hours, \fBw\fR for weeks, \fBm\fR for months (30 days) or \fBy\fR for years.
372 There are also two special values for period: \fBnow\fR and \fBnever\fR.
373 "\fB\fR\fB-p\fR \fBnow\fR" forces log rotation. "\fB\fR\fB-p\fR \fBnever\fR"
374 forces no log rotation.
380 \fB\fB-P\fR \fItimestamp\fR\fR
384 Used by \fBlogadm\fR to record the last time the log was rotated in
385 \fB/etc/logadm.conf\fR.
387 This option uses \fItimestamp\fR to determine if the log rotation period has
388 passed. The format of \fItimestamp\fR matches the format generated by
389 \fBctime\fR(3C), with quotes around it to protect embedded spaces.
390 \fItimestamp\fR is always recorded in the Coordinated Universal Time (UTC)
401 Remove any entries corresponding to the specified \fIlogname\fR from the
402 \fB/etc/logadm.conf\fR.
408 \fB\fB-R\fR \fIcmd\fR\fR
412 Run the \fIcmd\fR when an old log file is created by a log rotation. If the
413 keyword \fB$file\fR is embedded in the specified command, it is expanded to the
414 name of the old log file just created by log rotation.
416 This option is useful for processing log file contents after rotating the log.
417 \fIcmd\fR is executed by passing it to \fBsh\fR \fB-c\fR. When rotating
418 multiple logs with one logadm command, the command supplied with \fB-R\fR is
419 executed once every time a log is rotated. This is useful for post-processing a
420 log file (that is, sorting it, removing uninteresting lines, etc.). The
421 \fB-a\fR option is a better choice for restarting daemons after log rotation.
427 \fB\fB-s\fR \fIsize\fR\fR
431 Rotate the log file only if its size is greater than or equal to \fIsize\fR.
433 Specify \fIsize\fR as a number followed by the letter \fBb\fR for bytes,
434 \fBk\fR for kilobytes, \fBm\fR for megabytes, or \fBg\fR for gigabytes.
440 \fB\fB-S\fR \fIsize\fR\fR
444 Delete the oldest versions until the total disk space used by the old log files
445 is less than the specified size.
447 Specify \fIsize\fR as a number followed by the letter \fBb\fR for bytes,
448 \fBk\fR for kilobytes, \fBm\fR for megabytes, or \fBg\fR for gigabytes.
454 \fB\fB-t\fR \fItemplate\fR\fR
458 Specify the template to use when renaming log files.
460 \fItemplate\fR can be a simple name, such as \fB/var/adm/oldfile\fR, or it can
461 contain special keywords which are expanded by \fBlogadm\fR and are in the form
462 \fB$\fR\fIword\fR. Allowed sequences are:
466 \fB$\fIbasename\fR\fR
470 The log file name, without the directory name
480 The directory of the file to be rotated
490 Expands to the output of \fBdomainname\fR
500 The full path name of the file to be rotated
510 Expands to the output of \fBuname\fR \fB-p\fR
520 Expands to the output of \fBuname\fR \fB-m\fR
530 The version number, \fB0\fR is most recent, \fB1\fR is next most recent, and so
541 The same as $\fIn\fR, but starts at \fB1\fR instead of zero
547 \fB$\fInodename\fR\fR
551 Expands to the output of \fBuname\fR \fB-n\fR
557 \fB$\fIplatform\fR\fR
561 Expands to the output of \fBuname\fR \fB-i\fR
571 Expands to the output of \fBuname\fR \fB-r\fR
581 The number of seconds since \fB00:00:00 UTC, January 1,1970\fR
587 \fB$\fIzonename\fR\fR
591 Expands to the output of \fBzonename\fR(1).
594 To actually have the dollar sign character in the file name, use \fB$$\fR. Any
595 percent sequences allowed by \fBstrftime\fR(3C) are also allowed, for example,
596 \fB%d\fR expands to the day of the month. To actually have a percent sign
597 character in the file name, use \fB%%\fR. Both dollar-sign keywords and percent
598 sequences can appear anywhere in the template. If the template results in a
599 pathname with non-existent directories, they are created as necessary when
600 rotating the log file.
602 If no \fB-t\fR option is specified, the default template is \fB$file.$n\fR.
603 Actual \fBrotation\fR of log files, where each version is shifted up until it
604 expires is done using the \fB$n\fR keyword. If the template does not contain
605 the \fB$n\fR keyword, the log file is simply renamed to the new name and then
606 the expire rules, if any, are applied.
612 \fB\fB-T\fR \fIpattern\fR\fR
616 Normally \fBlogadm\fR looks for a list of old log files by turning the template
617 (specified with the \fB-t\fR option) into a pattern and finding existing files
618 whose names match that pattern. The \fB-T\fR option causes the given pattern to
621 This option is useful if another program fiddles with the old log file names,
622 like a \fBcron\fR job to compress them over time. The pattern is in the form of
623 a pathname with special characters such as \fB*\fR and \fB?\fR as supported by
624 \fBcsh\fR(1) filename substitution.
634 Print information about the actions being executed in verbose mode.
644 Validate the configuration file.
646 This option validates that an entry for the specified \fIlogname\fR exists in
647 the \fB/etc/logadm.conf\fR file and is syntactically correct. If \fIlogname\fR
648 is not specified, all entries in the configuration file are validated. If a
649 \fBlogname\fR argument is specified, the command validates the syntax of that
650 entry. If the entry is found, it is printed and the exit value of the command
651 is true. Otherwise the exit value is false.
657 \fB\fB-w\fR \fIentryname\fR\fR
661 Write an entry into the config file (that is, \fB/etc/logadm.conf\fR) that
662 corresponds to the current command line arguments. If an entry already existed
663 for the specified \fIentryname\fR, it is removed first. This is the preferred
664 method for updating \fB/etc/logadm.conf\fR, because it prevents syntax errors.
665 The \fIentryname\fR is an argument to an invocation of \fBlogadm\fR.
666 \fIentryname\fR might be chosen as something easy to remember or it can be the
667 pathname of the log file. If a pathname, rather than a name is used, it must be
668 a fully qualified pathname.
670 If no log file name is provided on a \fBlogadm\fR command line, the entry name
671 is assumed to be the same as the log file name. For example, the following two
672 lines achieve the same thing, keeping two copies of rotated log files:
676 % logadm -C2 -w mylog /my/really/long/log/file/name
677 % logadm -C2 -w /my/really/long/log/file/name
687 \fB\fB-z\fR \fIcount\fR\fR
691 Compress old log files after all other commands have been executed. \fIcount\fR
692 of the most recent log files are left uncompressed, therefore making the
693 \fIcount\fR most recent files easier to peruse. Use \fIcount\fR of zero to
694 compress all old logs.
696 The compression is done with \fBgzip\fR(1) and the resulting log file has the
697 suffix of \fB\&.gz\fR.
703 The following operands are supported:
711 Identifies the name of the entry in \fB/etc/logadm.conf\fR. If the log file
712 name is specified in the \fIlogname\fR field, it is assumed that \fIlogname\fR
713 is the same as the actual log file name.
718 \fBExample 1 \fRRotating a File and Keeping Previous Versions
721 The following example rotates the \fB/var/adm/exacct/proc\fR file, keeping ten
722 previous versions in \fB/var/adm/exacct/proc.0\fR through
723 \fB/var/adm/exacct/proc.9\fR.
727 Tell \fBlogadm\fR to copy the file and truncate it.
732 % logadm -c /var/adm/exacct/proc
738 \fBExample 2 \fRRotating syslog
741 The following example rotates \fBsyslog\fR and keeps eight log files. Old log
742 files are put in the directory \fB/var/oldlogs\fR instead of \fB/var/log\fR:
747 % logadm -C8 -t'/var/oldlogs/syslog.$n' /var/log/syslog
753 \fBExample 3 \fRRotating /var/adm/sulog and Expiring Based on Age
756 The following entry in the \fB/etc/logadm.conf\fR file rotates the
757 \fB/var/adm/sulog\fR file and expires any copies older than 30 days.
762 /var/adm/sulog -A 30d
768 \fBExample 4 \fRRotating Files and Expiring Based on Disk Usage
771 The following entry in the \fB/etc/logadm.conf\fR file rotates the
772 \fB/var/adm/sulog\fR file and expires old log files when more than 100
773 megabytes are used by the sum of all the rotated log files.
778 /var/adm/sulog -S 100m
784 \fBExample 5 \fRCreating an Entry that Stores the Logfile Name
787 This example creates an entry storing the log file name and the fact that we
788 want to keep 20 copies in \fB/etc/logadm.conf\fR, but the \fB\fR\fB-p\fR
789 \fBnever\fR means the entry is ignored by the normal \fBlogadm\fR run from
790 root's crontab every morning.
795 % logadm -w locallog /usr/local/logfile -C20 -p never
802 Use the following entry on the command line to override the \fB\fR\fB-p\fR
808 % logadm -p now locallog
814 \fBExample 6 \fRRotating the apache Error and Access Logs
817 The following example rotates the apache error and access logs monthly to
818 filenames based on current year and month. It keeps the 24 most recent copies
819 and tells apache to restart after renaming the logs.
823 This command is run once, and since the \fB-w\fR option is specified, an entry
824 is made in \fB/etc/logadm.conf\fR so the apache logs are rotated from now on.
829 % logadm -w apache -p 1m -C 24\e
830 -t '/var/apache/old-logs/$basename.%Y-%m'\e
831 -a '/usr/apache/bin/apachectl graceful'\e
832 '/var/apache/logs/*{access,error}_log'
839 This example also illustrates that the entry name supplied with the \fB-w\fR
840 option doesn't have to match the log file name. In this example, the entry name
841 is \fBapache\fR and once the line has been run, the entry in
842 \fB/etc/logadm.conf\fR can be forced to run by executing the following command:
847 % logadm -p now apache
854 Because the expression matching the apache log file names was enclosed in
855 quotes, the expression is stored in \fB/etc/logadm.conf\fR, rather than the
856 list of files that it expands to. This means that each time \fBlogadm\fR runs
857 from \fBcron\fR it expands that expression and checks all the log files in the
858 resulting list to see if they need rotating.
862 The following command is an example without the quotes around the log name
863 expression. The shell expands the last argument into a list of log files that
864 exist at the time the command is entered, and writes an entry to
865 \fB/etc/logadm.conf\fR that rotates the files.
870 logadm -w apache /var/apache/logs/*_log
879 \fB\fB/etc/logadm.conf\fR\fR
883 configuration file for \fBlogadm\fR command
889 See \fBattributes\fR(5) for descriptions of the following attributes:
897 ATTRIBUTE TYPE ATTRIBUTE VALUE
899 Interface Stability Evolving
905 \fBchgrp\fR(1), \fBchmod\fR(1), \fBchown\fR(1), \fBcsh\fR(1), \fBgzip\fR(1),
906 \fBcron\fR(1M), \fBctime\fR(3C), \fBstrftime\fR(3C), \fBlogadm.conf\fR(4),
911 When \fBlogadm\fR applies expire conditions (supplied by the \fB-A\fR,
912 \fB-C\fR, and \fB-S\fR options), it deletes files, the oldest first, until the
913 conditions are satisfied. If the template used for naming the old logs
914 contained \fB$n\fR or \fB$N\fR, \fBlogadm\fR picks the highest value of
915 \fB$n\fR or \fB$N\fR found in the old log file names first. If the template
916 used is something else, \fBlogadm\fR uses the modification time to determine
917 which files to expire first. This may not be the expected behavior if an old
918 log file has been modified since it was rotated.
921 Depending on log file sizes and number of log files, log file rotations can be
925 By default, \fBlogadm\fR works in \fBGMT\fR. Therefore, all entries written to
926 the \fB/etc/logadm.conf\fR file (see \fBlogadm.conf\fR(4)) will have a
927 \fBGMT\fR timestamp. Users can use the \fB-l\fR option to set \fBlogadm\fR to