socsvn commit: r236521 -
soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport
tzabal at FreeBSD.org
tzabal at FreeBSD.org
Sat May 26 21:09:43 UTC 2012
Author: tzabal
Date: Sat May 26 21:09:40 2012
New Revision: 236521
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236521
Log:
Updated version of the /usr/sbin/crashreport shell script. At this point, we should be able to locate the debugging information and check the email address either automatically (during boot) or manually.
Modified:
soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh
Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh
==============================================================================
--- soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Sat May 26 20:13:24 2012 (r236520)
+++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Sat May 26 21:09:40 2012 (r236521)
@@ -1,27 +1,32 @@
#!/bin/sh
+. /etc/rc.conf
+
print_usage()
{
echo "usage: $(basename $0) [-d dumpdir] [-f file] [-e email]"
}
-# Default dump directory
+
+# Constants
DUMPDIR='/var/crash'
-dumpdir=
-file=
-email=
+# Script variables
+_dumpdir=""
+_file=""
+_email=""
+
while getopts "d:f:e:" opt; do
case "$opt" in
d)
- dumpdir=$OPTARG
+ _dumpdir=$OPTARG
;;
f)
- file=$OPTARG
+ _file=$OPTARG
;;
e)
- email=$OPTARG
+ _email=$OPTARG
;;
*)
print_usage
@@ -30,42 +35,94 @@
esac
done
-
-if [ -z "${dumpdir}" ]; then
- if [ -d "${DUMPDIR}" ]; then
- dumpdir=${DUMPDIR}
+echo 'We start with:'
+echo "_dumpdir = ${_dumpdir}"
+echo "_file = ${_file}"
+echo "_email = ${_email}"
+echo '---------------'
+echo 'We end up with:'
+
+## Find the dump directory
+# Check the parameter
+if [ -z "${_dumpdir}" ]; then
+ # Check the dumpdir of /etc/rc.conf
+ if [ -z "${dumpdir}" ]; then
+ # Use the default dumpdir
+ _dumpdir=${DUMPDIR}
else
- echo "Dump directory does not exist."
- exit 1
+ _dumpdir=${dumpdir}
fi
fi
+if [ ! -d "${_dumpdir}" ]; then
+ echo "crashreport: Dump directory ${_dumpdir} does not exist."
+ exit 1
+fi
-BOUNDS="${dumpdir}/bounds"
-CORETXT="${dumpdir}/core.txt"
-TEXTDUMPTAR="${dumpdir}/textdump.tar"
-X=
-
-if [ -z "`ls ${dumpdir}`" ]; then
- echo "The dump directory is empty."
+if [ -z "`ls ${_dumpdir}`" ]; then
+ echo "crashreport: Dump directory ${_dumpdir} is empty."
exit 2
fi
+echo "_dumpdir = ${_dumpdir}"
-if [ -z "${file}" ]; then
- if [ -f "${BOUNDS}" ]; then
+## Find the file that contains the debugging information
+## It is either a core.txt.X or a textdump.tar.X
+BOUNDS="${_dumpdir}/bounds"
+CORE="${_dumpdir}/core.txt"
+TEXTDUMP="${_dumpdir}/textdump.tar"
+X=""
+
+# Check the parameter
+if [ -z "${_file}" ]; then
+ # Find it using the file bounds
+ if [ -r "${BOUNDS}" ]; then
value=`head -n 1 ${BOUNDS}`
X=$((value - 1))
- if [ -f "${CORETXT}.${X}" ]; then
- file=`basename "${CORETXT}.${X}"`
- elif [ -f "${TEXTDUMPTAR}.${X}" ]; then
- file=`basename "${TEXTDUMPTAR}.${X}"`
+ if [ -f "${CORE}.${X}" ]; then
+ _file=`basename "${CORE}.${X}"`
else
- echo "Unable to locate generated debugging information."
- exit 3
+ _file=`basename "${TEXTDUMP}.${X}"`
fi
+ # Otherwise, use this (heavier) way
else
- tmp=`ls | grep '[a-z]*\.[a-z]*\.\w*' | sort -n -t . -k 3 | tail -1`
- file=`basename "${tmp}"`
+ _file=`ls ${_dumpdir} | grep '[a-z]*\.[a-z]*\.\w*' | \
+ sort -n -t . -k 3 | tail -1`
fi
fi
+
+if [ ! -f "${_dumpdir}/${_file}" ]; then
+ echo "crashreport: Unable to locate file with debugging information."
+ exit 3
+fi
+
+echo "_file = ${_file}"
+
+## Find the email that will be used for contact
+# Check the parameter
+if [ -z "${_email}" ]; then
+ # The email of /etc/rc.conf
+ _email="${email}"
+fi
+
+if [ -z "$_email" ]; then
+ echo 'crashreport: No email address for contact is specified.'
+ exit 4
+fi
+
+# Check if the given email address is valid based on its format.
+echo ${_email} | egrep '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$' \
+ > /dev/null
+
+if [ "$?" -ne "0" ]; then
+ echo "Email address ${_email} is invalid."
+ exit 5
+fi
+
+echo "_email = ${_email}"
+
+## Send the report
+echo 'Sending the report...'
+
+# Everything went smooth
+exit 0
\ No newline at end of file
More information about the svn-soc-all
mailing list