DansGuardian Documentation Wiki

You are here: Main Index » capturing_problems


|

Wiki Information

Capturing Problems

Is DansGuardian failing, but you don't know why? And worse, you don't know what information to capture so others can help (or don't know which commands to use to capture it)? Or the system is administered by a helper or a coworker who knows almost nothing about Linux?

Just install this script, then when a problem occurs simply execute   danshung. It will do all the work for you automagically. You can then simply send or post the recorded file to anyone that might help.

To install this script, just copy&paste it from your browser window to your DansGuardian system as  /usr/sbin/danshung. (Be sure to set execute permissions if necessary, perhaps via  chmod a+x /usr/sbin/danshung.)

In most cases the location of the recorded file will be set automatically to a value appropriate to your system. (The selected actual path/name of the recorded file will be reported to you by the script itself.) If for some reason you wish to override automatic selection and force the recorded file to a location of your choosing, set environment variable RECORDFILE to your desired path/filename before executing  danshung.

#!/bin/bash

# Don't worry about some programs not being found.
# BASH will just continue (after issuing an error message); this is BASH's default behavior.


PROGNAME=`basename $0`
VERSION=6
if [[ ( -d /usr/local/var/log/dansguardian ) && ( ! -h /usr/local/var/log/dansguardian ) ]]; then RECORDFILE=${RECORDFILE:-/usr/local/var/log/danshung}; fi
if [[ ( -d /var/log/dansguardian ) && ( ! -h /var/log/dansguardian ) ]]; then RECORDFILE=${RECORDFILE:-/var/log/danshung}; fi
RECORDFILE=${RECORDFILE:-/var/log/danshung}
if [[ "$RECORDFILE" != /* ]]; then RECORDFILE=`pwd`/$RECORDFILE; fi

# disallow interruption by user (^C, kill, etc.)
trap '' SIGINT
trap '' SIGQUIT
# continue on error (such as program not found)
trap - ERR


echo ""
echo "Please type a short description of the current state of the system,"
echo " (DansGuardian is unresponsive so the web is inaccessible,"
echo " DansGuardian won't start, DansGuardian just crashed, DansGuardian"
echo " is up but it doesn't work right, etc.), then press ENTER"
read -p "Description? > " CURSTATE
echo ""

echo "** Recording DansGuardian/Squid/OS system state in $RECORDFILE **"
echo ""


MESSAGE="%%%%% `date '+%T %Z %D'` - $PROGNAME v$VERSION: beginning report because: $CURSTATE"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE

USERLOG=(`logger -p user.err "$PROGNAME v$VERSION searching for user log" ; sleep 1 ; sleep 1 ; find /var/log -maxdepth 1 -type f -mmin 1`)
if [[ -z "$USERLOG" ]]; then USERLOG=/dev/null; fi
KERNLOG=(`logger -p kern.err "$PROGNAME v$VERSION searching for user log" ; sleep 1 ; sleep 1 ; find /var/log -maxdepth 1 -type f -mmin 1`)
if [[ -z "$KERNLOG" ]]; then KERNLOG=/dev/null; fi
if [[ ( -d /usr/local/etc/dansguardian ) && ( ! -h /usr/local/etc/dansguardian ) ]]; then
	DGCONFIGDIR=${DGCONFIGDIR:-/usr/local/etc/dansguardian}
elif [[ ( -d /etc/dansguardian ) && ( ! -h /etc/dansguardian ) ]]; then
	DGCONFIGDIR=${DGCONFIGDIR:-/etc/dansguardian}
else
	DGCONFIGDIR=${DGCONFIGDIR:-/}
fi
if [[ -d /etc/squid ]]; then
	SQUIDCONFIGDIR=${SQUIDCONFIGDIR:-/etc/squid}
else 
	SQUIDCONFIGDIR=${SQUIDCONFIGDIR:-/}
fi


MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: next show who am i w/ id"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
id >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: id done, next DansGuardian (PATH) version"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
dansguardian -v >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: DansGuardian (PATH) done, next DansGuardian (/sbin) version"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
/sbin/dansguardian -v >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: DansGuardian (/sbin) done, next DansGuardian (/usr/local/sbin) version"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
/usr/local/sbin/dansguardian -v >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: DansGuardian (/usr/local/sbin) version done, next kernel/hostname/version"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
uname -a >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: kernel version done, next show where am i w/ tty"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
tty >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: tty done, next dmesg"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
dmesg >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: dmesg done, next the dansguardian.conf in $DGCONFIGDIR"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
cat $DGCONFIGDIR/dansguardian.conf >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: dansguardian.conf done, next the dansguardianf1.conf in $DGCONFIGDIR"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
cat $DGCONFIGDIR/dansguardianf1.conf >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: dansguardianf1.conf, next the squid.conf in $SQUIDCONFIGDIR"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
cat $SQUIDCONFIGDIR/squid.conf >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: squid.conf done, next which dansguardian is on PATH"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
which dansguardian >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: which executable done, next 2.8 vs. 2.9/2.10 file paths"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
ls -ld /sbin/dansguardian /usr/local/sbin/dansguardian /etc/dansguardian/dansguardian.conf /usr/local/etc/dansguardian/dansguardian.conf /var/log/dansguardian /usr/local/var/log/dansguardian >> $RECORDFILE 2>&1

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: list files done, next record processes w/ ps"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
ps aux >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: ps done, next record processes w/ top"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
top -b -n 1 >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: top done, next show runlevel"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
runlevel >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: runlevel done, next show NICs w/ ifconfig -a"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
/sbin/ifconfig -a >> $RECORDFILE

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: ifconfig done, next show mounts w/ df -a"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
df -a >> $RECORDFILE

df -a | while read -a LINE
do
	if [[ "$LINE" == /dev/* ]]
	then
		MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: going to access device $LINE"
		echo $MESSAGE
		echo $MESSAGE >> $RECORDFILE
		head -1 "$LINE" >> $RECORDFILE
		MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: done accessing $LINE"
		echo $MESSAGE
		echo $MESSAGE >> $RECORDFILE
	fi
done

MESSAGE="===== `date '+%T %Z %D'` - $PROGNAME v$VERSION: ending"
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE
MESSAGE=""
echo $MESSAGE
echo $MESSAGE >> $RECORDFILE

echo "** DansGuardian/Squid/OS SYSTEM STATE CAPTURED,"
echo "   SEND/POST(in body) CONTENTS OF FILE  $RECORDFILE  FOR AID **"
echo "   (But don't ATTACH when posting to DansGuardian mailing list;"
echo "    the list will throw away attachments and nobody will ever see them.)"