Hi eantoranz,
Several years ago I got an script on internet which opens the core file, prints the back trace and the program name on the standard output without getting the prompt. I used it to scan several core dumps and save the bt with the program name onto a file to identify problems on my customers. As a source is worth a thousand words, I'm posting the script here:
Code:
osvaldo@osvaldo:~$ cat /util/idcore
#!/bin/sh
# name: idcore -- identify which binary caused a core dump
# author: c.l.s. (cspiel@physik.tu-muenchen.de)
# last rev.: 1998-01-22 11:14
# bash ver.: 1.14.7(1)
# $Id$
# display help message
# char* disp_help(void)
function disp_help
{
echo "usage:"
echo " idcore [OPTION] [[COREDUMP] ...]"
echo
echo " If COREDUMP is omitted the core file in the current"
echo " directory is used."
echo
echo " -h, --help display this help message"
echo " -v, --version show version of idcore"
echo " -b, --brief brief format, i.e. filename only"
echo " -l, --long long format, with filename, signal, user,"
echo " date, and backtrace"
}
# retrieve name binary that caused core dump via gdb
# char* get_name(const char* mode, const char* name)
function get_name
{
case "$1" in
brief)
echo q | gdb --quiet --core="$2" 2>&1 | head -1 | \
sed -ne "s/^.*\`\(.*\)'\.$/\1/g;s/ .*$//p"
;;
standard)
echo q | gdb --quiet --core="$2" 2>&1 | head -2
;;
long)
execp=$(idcore --brief $2)
echo $execp
if [ ! "$execp" = "" ] && [ -x $execp ]
then
dump=$(echo -e "where\nq" | \
gdb --quiet --core="$2" "$execp" 2>&1)
else
dump=$(echo -e "where\nq" | \
gdb --quiet --core="$2" 2>&1)
fi
echo "$dump" | head -2 | sed -ne '2,2s/\.$//p'
ls -l "$2" | \
awk '{ print "on", $6, $7, $8, "caused by", $3 }'
echo
echo "backtrace:"
echo "$dump" | sed -e 's/^(gdb) //p' | grep '^#' | awk '{ if ($0 != ant)
{
ant = $0
print $0}
}'
;;
esac
}
#
# start of main
#
myname=$(basename "$0") # name of shell-script
mode=standard # normal mode of operation
case "$1" in
-h | --help)
disp_help
exit 1
;;
-v | --version)
echo "version 0.1.0"
exit 0
;;
-b | --brief)
mode=brief
shift
;;
-l | --long)
mode=long
shift
;;
-* | --*)
echo "$myname: unknown option $1"
exit 2
;;
esac
if [ -z "$1" ]; then
# no argument -> look at core in the current directory
get_name "$mode" core
else
# process all arguments
for c; do
# echo file we are processing
if [ "$mode" != "brief" ]; then
echo "$c: "
fi
get_name "$mode" "$c"
done
fi
exit 0
Have fun!
Osvaldo.