O'Reilly logo

Essential SNMP by Kevin Schmidt, Douglas Mauro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required