Throw Core

Programs frequently leave core dumps behind. A core file contains all the process information pertinent to debugging. It usually gets written when a program dies abnormally. While there are ways to limit the size of a dump or prevent core dumps entirely, there are still times when they’re needed temporarily. Therefore, most Unix systems have some sort of cron script that automatically searches for core files and deletes them. Let’s add some intelligence to these scripts to let us track what files are found, their sizes, and the names of the processes that created them.

The following Perl program is divided into four parts: it searches for a file with a given name (defaults to the name core), gets the file’s statistics, deletes the file,[64] and then sends a trap. Most of the processing is performed natively by Perl, but we use the command ls -l $FILENAME to include the pertinent core file information within the SNMP trap. This command allows our operators to see information about the file in a format that’s easy to recognize. We also use the file command, which determines a file’s type and its creator. Unless you know who created the file, you won’t have the chance to fix the real problem.

#!/usr/local/bin/perl # Finds and deletes core files. It sends traps upon completion and # errors. Arguments are: # -path directory : search directory (and subdirectories); default / # -lookfor filename : filename to search for; default core # -debug value : debug level while ...

Get Essential SNMP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.