blob: 9dfe357d012f13e18c3807adba7645bce97e5173 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2# Shell script compatibility wrapper for /sbin/logread
3#
4# Copyright (C) 2019 Dirk Brenken <dev@brenken.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20
21logfile="/var/log/messages"
22
23if [ ! -f "${logfile}" ]
24then
25 printf "%s\n" "Error: logfile not found!"
26 exit 2
27fi
28
29usage()
30{
31 printf "%s\n" "Usage: logread [options]"
32 printf "%s\n" "Options:"
33 printf "%5s %-10s%s\n" "-l" "<count>" "Got only the last 'count' messages"
34 printf "%5s %-10s%s\n" "-e" "<pattern>" "Filter messages with a regexp"
35 printf "%5s %-10s%s\n" "-f" "" "Follow log messages"
36 printf "%5s %-10s%s\n" "-h" "" "Print this help message"
37}
38
39if [ -z "${1}" ]
40then
41 cat "${logfile}"
42 exit 0
43else
44 while [ "${1}" ]
45 do
46 case "${1}" in
47 -l)
48 shift
49 count="${1//[^0-9]/}"
50 tail -n "${count:-50}" "${logfile}"
51 exit 0
52 ;;
53 -e)
54 shift
55 pattern="${1}"
56 grep -E "${pattern}" "${logfile}"
57 exit 0
58 ;;
59 -f)
60 tail -f "${logfile}"
61 exit 0
62 ;;
63 -fe)
64 shift
65 pattern="${1}"
66 tail -f "${logfile}" | grep -E "${pattern}"
67 exit 0
68 ;;
69 -h|*)
70 usage
71 exit 1
72 ;;
73 esac
74 shift
75 done
76fi