slightly tricky way of capturing additions to a logfile

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Tue Aug 13 05:03:40 UTC 2013


Background (can be skipped):

I'm having problems with grub.

Ubuntu has a bug where it won't add grub entries for other installed
linuxes UNLESS their /boot is mounted.  The fix is upstream (debian)
for six months or so but they haven't shipped it (althuogh it is
marked as "fix-released"):
<https://bugs.launchpad.net/ubuntu/+source/os-prober/+bug/1038093>

Fedora had a similar bug.  They wouldn't add grub entries for other
installed Linuxes unless the partition with /boot had SELinux security
labels.  Rather a rude requirement considering those labels don't do
Ubuntu any good.  That one has been fixed:
<https://bugzilla.redhat.com/show_bug.cgi?id=882568>

So I found a similar-looking bug in Fedora-19 on the weekend and
misdiagnosed it <https://bugzilla.redhat.com/show_bug.cgi?id=995777>
I don't yet know what the bug is.

The Red hat maintainer(?) asked me to run os-prober, the thing that is
supposed to find other operating systems when generating a grub config
file (unless grubby is being used).  He wanted to see what was logged
to /var/log/messages


Foreground:

Here are the slightly tricky shell commands I used:

[root at redcherry-mimosa-com hugh]# exec {log}</var/log/messages
[root at redcherry-mimosa-com hugh]# cat <&${log} >/dev/null
[root at redcherry-mimosa-com hugh]# cat <&${log}
[root at redcherry-mimosa-com hugh]# os-prober
/dev/sda1:FreeDOS:FreeDOS:chain
[root at redcherry-mimosa-com hugh]# cat <&${log}
 ...

(all the newly added stuff appeared.)

How this worked:

	exec {log}</var/log/messages

an exec shell command can be used to modify redirections for the
running shell, not a subshell.  Kind of magical, but a longstanding
feature.

This particular redirectly command (I think that it is a BASH
extension) uses a file descriptor of bash's choosing and places the
number in the variable "log".  That seems cleaner than my choosing a
filedescriptor to use.

	cat <&${log} >/dev/null

this reads everything from that file descriptor and throws it away.

	cat <&${log}

This just shows that there is nothing remaining.

	os-prober

This runs the command that might produce interesting log output.

	cat <&${log}

This command cats all that has been added to the log since the last
one.

NOTE: this will fail if log rotation occurs at an inconvenient time.
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list