]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/btraceback.in
a066cee935021fdb11c64df2e3f7f26fb8649cee
[bacula/bacula] / bacula / scripts / btraceback.in
1 #!/bin/sh
2 #
3 # Script to do a stackdump of a Bacula daemon/program.
4 #
5 # Author: Kern Sibbald, 2002
6 # License: LGPLv3
7 #
8 # We attempt to attach to running program
9 #
10 # Arguments to this script are
11 #  $1 = path to executable
12 #  $2 = main pid of running program to be traced back.
13 #  $3 = working directory
14 #
15 PNAME=`basename $1`
16 WD="$3"
17 case `uname -s` in
18 SunOS)
19    #
20    # See what debuggers are available on this platform.
21    # We need to to some tricks to find out as a which on
22    # a non existing binary gives:
23    #
24    # no <debugger> in <PATH>
25    #
26    # So we use the return code which is 0 when it finds
27    # somethings and 1 if not.
28    #
29    which gdb > /dev/null 2>&1 && GDB=`which gdb` || GDB=''
30    which dbx > /dev/null 2>&1 && DBX=`which dbx` || DBX=''
31    which mdb > /dev/null 2>&1 && MDB=`which mdb` || MDB=''
32    gcore -o ${WD}/${PNAME} $2
33    if [ ! -z "${DBX}" ]; then
34       ${DBX} $1 $2 < @scriptdir@/btraceback.dbx > ${WD}/bacula.$2.traceback 2>&1
35    elif [ ! -z "${GDB}" ]; then
36       ${GDB} -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 > ${WD}/bacula.$2.traceback 2>&1
37    elif [ ! -z "${MDB}" ]; then
38       ${MDB} -u -p $2 < @scriptdir@/btraceback.mdb > ${WD}/bacula.$2.traceback 2>&1
39    fi
40    PNAME="${PNAME} on `hostname`"
41    cat ${WD}/bacula.$2.traceback \
42     | @sbindir@/bsmtp -h @smtp_host@ -f @dump_email@ -s "Bacula DBX traceback of ${PNAME}" @dump_email@
43    ;;
44 *)
45    gdb -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 >${WD}/bacula.$2.traceback 2>&1
46    PNAME="${PNAME} on `hostname`"
47    cat ${WD}/bacula.$2.traceback \
48     | @sbindir@/bsmtp -h @smtp_host@ -f @dump_email@ -s "Bacula GDB traceback of ${PNAME}" @dump_email@
49    ;;
50 esac