From: Karel Zak Date: Wed, 21 Oct 2020 10:03:45 +0000 (+0200) Subject: dmesg: add --since and --until X-Git-Tag: v2.37-rc1~405 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=732d75945ef5a299f08d60c6f8b28152b8b38bbc;p=thirdparty%2Futil-linux.git dmesg: add --since and --until $ date Wed 21 Oct 2020 12:05:07 PM CEST $ dmesg --ctime --since '1 hour ago' [Wed Oct 21 11:47:13 2020] AAA [Wed Oct 21 11:55:48 2020] BBB $ dmesg --ctime --since '1 hour ago' --until '10 minutes ago' [Wed Oct 21 11:47:13 2020] AAA Addresses: https://github.com/karelzak/util-linux/issues/1166 Signed-off-by: Karel Zak --- diff --git a/bash-completion/dmesg b/bash-completion/dmesg index 02f2fc7a62..00772993c2 100644 --- a/bash-completion/dmesg +++ b/bash-completion/dmesg @@ -57,6 +57,8 @@ _dmesg_module() --follow --follow-new --decode + --since + --until --help --version" COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) diff --git a/sys-utils/dmesg.1 b/sys-utils/dmesg.1 index 4bec7892bb..b38766826c 100644 --- a/sys-utils/dmesg.1 +++ b/sys-utils/dmesg.1 @@ -162,6 +162,14 @@ system .BR SUSPEND / RESUME . Timestamps are adjusted according to current delta between boottime and monotonic clocks, this works only for messages printed after last resume. +.IP "\fB\-\-since \fItime\fR" +Display record since the specified time. The time is possible to specify in absolute way +as well as by relative notation (e.g. '1 hour ago'). Be aware that the timestamp could +be inaccurate and see \fB\-\-ctime\fR for more details. +.IP "\fB\-\-until \fItime\fR" +Display record until the specified time. The time is possible to specify in absolute way +as well as by relative notation (e.g. '1 hour ago'). Be aware that the timestamp could +be inaccurate and see \fB\-\-ctime\fR for more details. .IP "\fB\-t\fR, \fB\-\-notime\fR" Do not print kernel's timestamps. .IP "\fB\-\-time\-format\fR \fIformat\fR" diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index c7759857e2..fa1dd2dffc 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -180,6 +180,9 @@ struct dmesg_control { ssize_t kmsg_first_read;/* initial read() return code */ char kmsg_buf[BUFSIZ];/* buffer to read kmsg data */ + time_t since; /* filter records by time */ + time_t until; /* filter records by time */ + /* * For the --file option we mmap whole file. The unnecessary (already * printed) pages are always unmapped. The result is that we have in @@ -303,6 +306,9 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" --time-format show timestamp using the given format:\n" " [delta|reltime|ctime|notime|iso]\n" "Suspending/resume will make ctime and iso timestamps inaccurate.\n"), out); + fputs(_(" --since