Skip to content

Instantly share code, notes, and snippets.

@Flova
Last active February 16, 2024 11:22
Show Gist options
  • Save Flova/94d07fbde37d033b4ee19af55d60a23a to your computer and use it in GitHub Desktop.
Save Flova/94d07fbde37d033b4ee19af55d60a23a to your computer and use it in GitHub Desktop.
Creates a memory dump of a running nginx. Usefull for getting lost config files from a running machine.
# Get the process id of nginx
NGINX_PID=$(pgrep -o 'nginx')
echo Nginx server PID: $NGINX_PID
# Get the memory parts that are used by nginx.
# That make gdb dump commands with it and dump the corresponding memory into files
cat /proc/$NGINX_PID/maps \
| awk '
$6 !~ "^/" {split ($1,address,"-");
print "dump memory mem_" address[1] " 0x" address[1] " 0x" address[2] ;}
END{print "quit"}' \
| tee /tmp/gdb_cmds
# Run gdb to dump the memory
gdb -p $NGINX_PID -x /tmp/gdb_cmds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment