parse a line for a particular value (specifically crashkernel)
We are reviewing our environment and best-practices. One of the items of consideration is crashkernel. I am trying to figure out how to parse grub.conf to determine what the crashkernel is set to at boot time via grub (I'm not interested in what /proc/cmdline has at that time).
Consider the following 2 scenarios:
# grep crash /boot/grub/grub.conf
kernel /vmlinuz-2.6.18-348.12.1.el5 ro root=/dev/VolGroup00/LogVol01 quiet crashkernel=auto
# grep crash /boot/grub/grub.conf
kernel /vmlinuz-2.6.18-348.4.1.el5 ro root=/dev/VolGroup00/LogVol01 rhgb quiet crashkernel=128M@16M
I would like to return either
crashkernel=auto or crashkernel=128M@16M
or.. better yet
auto or 128M@16M
Responses
Couple questions:
1) what's your preferred programming language (shell, Perl, Python, etc.)
2) do your systems have more than one boot-entry configured in grub
2a) If 'yes' to '2', do you want to parse all of the bootable options or just a specific one?
Well then, here are some ideas:
-
I'd start with the following to ensure you only get uncommented kernel lines containing crashkernel
egrep '^[[:space:]]*kernel /vmlinuz.*crashkernel=' /etc/grub.conf -
Then I'd pass that to either
sedorawk(orgrep+cut), e.g.:egrep -o crashkernel=[[:graph:]]+ | cut -d= -f2 | head -1 ... or ... awk 'NR==1 { print gensub(/.*crashkernel=([[:graph:]]+).*/, "\\1", 1) }' ... or ... sed -r '1!d;s/.*crashkernel=([[:graph:]]+).*/\1/' -
If you'd prefer to see all results and not just the first one, get rid of the leading
NR==1in the awk command and the leading1!d;in the sed command.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
