Line 0
Link Here
|
|
|
1 |
#!/bin/sh |
2 |
# $FreeBSD$ |
3 |
# |
4 |
# Copyright (c) 2012 The FreeBSD Project. |
5 |
# All rights reserved. |
6 |
# |
7 |
# Redistribution and use in source and binary forms, with or without |
8 |
# modification, are permitted provided that the following conditions |
9 |
# are met: |
10 |
# 1. Redistributions of source code must retain the above copyright |
11 |
# notice, this list of conditions and the following disclaimer. |
12 |
# 2. Redistributions in binary form must reproduce the above copyright |
13 |
# notice, this list of conditions and the following disclaimer in the |
14 |
# documentation and/or other materials provided with the distribution. |
15 |
# |
16 |
# THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS |
17 |
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 |
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 |
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 |
# POSSIBILITY OF SUCH DAMAGE. |
27 |
# |
28 |
# periodic.subr |
29 |
# functions used by periodic(5) scripts |
30 |
# |
31 |
|
32 |
: ${rcvar_manpage:='periodic.conf(5)'} |
33 |
|
34 |
if [ -z "${_periodic_subr_loaded}" ]; then |
35 |
|
36 |
_periodic_subr_loaded="YES" |
37 |
|
38 |
# If there is a global system configuration file, suck it in. |
39 |
# |
40 |
if [ -r /etc/defaults/periodic.conf ]; then |
41 |
. /etc/defaults/periodic.conf |
42 |
source_periodic_confs |
43 |
fi |
44 |
|
45 |
. /etc/rc.subr |
46 |
|
47 |
# Cat out a [compressed] set of log(s). |
48 |
# |
49 |
# Parameters: |
50 |
# 1 - log directory. |
51 |
# 2 - log basename, e.g. auth, messages, etc. |
52 |
catlogs() { |
53 |
local _logdir _log_basename rc |
54 |
|
55 |
_logdir="$1" |
56 |
_log_basename="$2" |
57 |
|
58 |
if [ ! -d "${_logdir:-}" ]; then |
59 |
err 3 "log directory specified - ${_logdir} doesn't exist" |
60 |
elif [ -z "${_log_basename:-}" ]; then |
61 |
err 3 "you must supply a non-zero length log basename" |
62 |
fi |
63 |
|
64 |
# Cat out the compressed logs. |
65 |
find "${_logdir}" -name "$log_basename.*" -mtime -2 | |
66 |
sort -t. -r -n -k 2,2 | |
67 |
while read f |
68 |
do |
69 |
case $f in |
70 |
*.gz) zcat -f $f;; |
71 |
*.bz2) bzcat -f $f;; |
72 |
esac |
73 |
done |
74 |
# Cat out the original log. |
75 |
if [ -f "$_logdir/$_log_basename" ]; then |
76 |
cat "$_logdir/$_log_basename" |
77 |
fi |
78 |
} |
79 |
|
80 |
fi # [ -z "${_periodic_subr_loaded}" ] |
81 |
|
82 |
_periodic_subr_loaded=: |