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