This answer is a small but I think useful addition to the brilliant top answer, so follow those directions first. Then you can use this script to more easily find your config.
Once you have the memory dumps from the top answer, you can use this slightly-overengineered Awk script to extract anything that looks like a top-level brace-enclosed configuration block.
#!/usr/bin/awk -f
### Setup
# We're searching for a keyword followed by an open brace to start
# And the a close brace at the start of a line to end
# Also include commented sections, cause otherwise they look funny
BEGIN {
start="[[:alpha:]_#]+ \\{$";
end="^#?}"
}
# Shortcut to extract a regex pattern from $0
function extract(ere) { return substr($0, match($0, ere), RLENGTH) }
# Check for end conditions first
# This way we end the section before we print below
# For the primary end condition, print out the matched bit
$0 ~ end { print extract(end); go=0}
# And a safety stop: bail on any non-printable lower-ASCII characters
/[\x00-\x08\x0e-\x19]/ { go=0 }
# If we're in a section, print the line!
go {print}
# Otherwise, check for our starting condition
# If we find it, print just that bit and turn on our flag
!go && $0 ~ start {
go=1;
print "### Extracted from memory dump:";
print extract(start)
}
Save that to extract.awk
and then run awk -f extract.awk mem_*
, or if you prefer one-liners, here you go:
awk 'BEGIN { start="[[:alpha:]_#]+ \\{$"; end="^#?}" } function extract(ere) { return substr($0, match($0, ere), RLENGTH) } $0 ~ end {print extract(end); go=0} /[\x00-\x08\x0e-\x19]/ { go=0 } go {print} !go && $0 ~ start { go=1; print "### Extracted from memory dump:"; print extract(start)}' mem_*
This script should dump a list of top-level config sections that you can then look through to recover the ones you need, without digging through a bunch of other memory noise.
Note: Awk may complain about malformed characters on STDERR, you can just ignore it. If you have recent GNU awk you can add the -b
flag indicate that you expect binary data, which will silence the warning.
But why?
Yeah, you can just grep through those dumps, or open them in an editor and search for blocks, but there will be small pieces of your config scattered throughout the memory map, so it can be annoying to dig through. strings
loses whitespace, and you can grep for things like a brace followed by a newline...but we have tools to help us do this. And if you're already copy-pasting scripts from ServerFault, you might as well do one more to make your life easier.