#!/bin/sh
# 
# Script to do a stackdump of a Bacula 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`
PNAME="${PNAME} on `hostname`"
WD="$3"
if test `uname -s` = SunOS ; then
  gcore -o ${WD}/${PNAME} $2
  dbx $1 $2 </usr/local/libexec/bacula/btraceback.dbx >${WD}/bacula.$2.traceback 2>&1
  cat ${WD}/bacula.$2.traceback \
   | /usr/local/sbin/bsmtp -h localhost -f root@localhost -s "Bacula DBX traceback of ${PNAME}" root@localhost
else
  gdb -quiet -batch -x /usr/local/libexec/bacula/btraceback.gdb $1 $2 >${WD}/bacula.$2.traceback 2>&1
  cat ${WD}/bacula.$2.traceback \
   | /usr/local/sbin/bsmtp -h localhost -f root@localhost -s "Bacula GDB traceback of ${PNAME}" root@localhost
fi 
