The --time-format long option for dmesg is a possibility using the iso format:
(note the T and no space between the date and the time, due to the iso format)
The sed only works if you have a line with 2022-12-12T09 and a line with 2022-12-12T10 in your logs.
$ sudo dmesg --time-format=iso | sed -n '/2022-12-12T09/,/2022-12-12T10/p'
You could alternatively do something like this to add more specificity to the time range (here, we are grabbing only the specified minutes in the range):
In this one, you'd also need a line with 2022-12-12T09:16 and a line with 2022-12-12T09:24 in your logs.
$ sudo dmesg --time-format=iso | sed -n '/2022-12-12T09:16/,/2022-12-12T09:24/p'
From the manpage
--time-format format
Print timestamps using the given format, which can be ctime, reltime, delta or iso. The first three formats are aliases of the
time-format-specific options. The iso format is a dmesg implementation of the ISO-8601 timestamp format.
The purpose of this format is to make the comparing of
timestamps between two systems, and any other parsing, easy. The definition
of the iso timestamp is: YYYY-MM-DDHH:MM:SS,<-+>.
The iso format has the same issue as ctime: the time may be
inaccurate when a system is suspended and resumed.
dmesg? https://man7.org/linux/man-pages/man1/dmesg.1.html – Romeo Ninov Dec 21 '22 at 18:15--time-formatoption in your dmesg version? It should be useful to know if you do it to can run this command and parse it correctly:sudo dmesg --time-format 'ctime'– Edgar Magallon Dec 22 '22 at 02:18journalctlis also able to showdmesgmessages by usingsudo journalctl -k(but given that you say thatjournalctldoes not have the options--sinceand--untilthen this is not so useful) – Edgar Magallon Dec 22 '22 at 02:20date -d $(dmesg -T --time-format iso | grep -w "oom-kill" | cut -d ',' -f 1) +%sto get the time of the log (in seconds from epoch) for doing comparison. – Damon Dec 22 '22 at 02:37sudo journalctl -k --since "2022-12-20 09:00:00" --until "2022-12-20 10:00:00" without having to parsedmesg. Hope that helps!– Edgar Magallon Dec 22 '22 at 04:23journalctl -kgives me this:-- Logs begin at Tue 2019-01-29 17:48:05 PST, end at Thu 2022-12-22 09:20:36 PST. -- -- No entries --– Damon Dec 22 '22 at 17:23sudo? I also have that output if I do not usesudo– Edgar Magallon Dec 22 '22 at 22:16dmesgon the container.dmesgworks in there since it shows the identical logs as physical host does. Butjournalctldoesn't show any logs on the container, only the physical host! Thank you! – Damon Dec 30 '22 at 19:51journalctldid not work. It'd be interesting ifjournalctlcan/could show logs from containers such aslxc,docker,podman(maybejournalctlcan get logs from containers created bysystemd-nspawn). I will search about that :). – Edgar Magallon Dec 30 '22 at 21:58