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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#!/bin/bash
#
# *****************************************************************
# * *
# * Copyright 2009 Hewlett-Packard Development Company, L.P. *
# * *
# * crashdc may be copied only under the terms of the GNU *
# * General Public License, which may be found in the source *
# * kit. *
# * *
# *****************************************************************
#
# HISTORY
#
typeset PROG=`basename $0`
typeset crashdc_version="0.08"
typeset -i error=0
if [[ -r /etc/sysconfig/crashdc ]];then
. /etc/sysconfig/crashdc
else
if [[ -r ./sysconfig.crashdc ]];then
. ./sysconfig.crashdc
else
echo "The file /etc/sysconfig/crashdc or ./sysconfig.crashdc is absent. Cannot run"
exit 1
fi
fi
build_cmd_file()
{
typeset mode=$1
typeset cmdfile=$2
#BASIC : ### Tool Information : help | grep crash
#BASIC : ### Crash Context Information : sys
#BASIC : ### Preserved Kernel Ring Buffer : log
#BASIC : ### Panic current process : set
#BASIC : ### Panic current process backtrace : bt
#BASIC : ### List of running processes : ps
#ADVANCED : ### List of running processes by Last Run Stamp : ps -t
#BASIC : ### List of process backtraces : foreach bt
#ADVANCED : ### List of process structures : foreach task
#ADVANCED : ### List of process open files : foreach files
#BASIC : ### List of mounted file systems : mount
#ADVANCED : ### Open files information for each file system : mount -f
#BASIC : ### Network information : net
#ADVANCED : ### Network socket information : foreach net -s
#BASIC : ### Kernel Module information : mod
#ADVANCED : ### Kernel Symbols information : sym -l
#ADVANCED : ### Kernel Memory information : kmem -i
#ADVANCED : ### Kernel Slab information : kmem -s
if [[ -z $cmdfile ]];then
cmdfile=$0
if [[ $mode == "ADVANCED" ]];then
mode="^#[AB]."
else
mode="^#BASIC"
fi
else
mode="."
fi
grep "$mode" $cmdfile | while read Line
do
Line=${Line#*: }
cmd_title=${Line%:*}
cmd_code=${Line#*: }
(( debug )) && echo "!echo -n \`date\`;echo \"${cmd_title}\"" >> $crashcmd
echo "!echo \"${cmd_title}\" >> $crashoutput" >> $crashcmd
echo "!echo \"crash> ${cmd_code}\" >> $crashoutput" >> $crashcmd
echo "${cmd_code} >> $crashoutput" >> $crashcmd
done
(( debug )) && echo "!echo -n \`date\`;echo \"### End of crashdc report\"" >> $crashcmd
echo "!echo \"### End of crashdc report\" >> $crashoutput" >> $crashcmd
echo "!echo \"crash> quit\" >> $crashoutput" >> $crashcmd
echo "quit >> $crashoutput" >> $crashcmd
}
typeset debug=99
typeset crashdebug=0
typeset usage="usage: $PROG [-h] [-b|-a|-c command file] [-V] [-d level] [-x /path/to/crash/exe] /path/to/namelist /path/to/vmcore /path/to/output/directory [/path/to/debuginfo/file]"
typeset crashexe="$CRASHEXE"
typeset crashcmd="${MOUNTPREFIX}/tmp/crashcmd.$$"
typeset crashdata="$CRASHDATA"
typeset crashmode="BASIC"
typeset crashcmdfile=""
typeset rundate="$(date +%Y%m%d%H%M)"
typeset prefix="$MOUNTPREFIX"
if ! [[ -d ${MOUNTPREFIX}/tmp ]];then
crashcmd="/tmp/crashcmd.$$"
fi
#
# Option parsing
#
while getopts ":bac:d:hVx:" options; do
case $options in
x ) crashexe=$OPTARG;;
h ) echo $usage
exit 0;;
d ) debug=$OPTARG;;
b ) crashmode="BASIC";;
a ) crashmode="ADVANCED";;
c ) crashmode="CUSTOM"
crashcmdfile=$OPTARG;;
V ) echo $crashdc_version
exit 0;;
\? ) echo $usage
exit 1;;
* ) echo $usage
exit 1;;
esac
done
shift $(($OPTIND-1))
typeset namelist=$1
typeset vmcorefile=$2
typeset crashoutputdir=$3
typeset debuginfofile=$4
typeset crashoutput="${crashoutputdir}/${crashdata}-${rundate}.txt"
if (( debug == 99 ));then
debug=0 # -d switch not used
elif (( debug == 0 ));then
debug=1
crashdebug=0
else
crashdebug=$debug
fi
#
# Verify location of debuginfo file
# Needed for SLES11 initrd environment
# which relocates the / to $MOUNTPREFIX at runtime
#
if ! [[ -r $debuginfofile ]] && ! [[ -z $debuginfofile ]] ;then
debuginfofile=${prefix}$debuginfofile
if ! [[ -r $debuginfofile ]];then
echo "Unable to locate ${debuginfofile#$prefix} or $debuginfofile."
echo "Giving up"
exit 1
fi
fi
(( debug )) && {
echo crashexe : $crashexe
echo crashoutput : $crashoutput
echo namelist : $namelist
echo vmcorefile : $vmcorefile
echo debuginfofile : $debuginfofile
}
if ! [[ -x $crashexe ]]; then
echo "Crash executable $crashexe cannot be found or is not executable"
exit 1
elif ! [[ -d $crashoutputdir ]];then
echo "Output directory $crashoutputdir cannot be found or is not readable"
exit 1
elif ! [[ -r $namelist ]];then
echo "Namelist file $namelist cannot be found or is not readable"
exit 1
elif ! [[ -r $vmcorefile ]];then
echo "Vmcore file $vmcorefile cannot be found or is not readable"
exit 1
fi
#
# All files are there & OK, let's proceed
#
build_cmd_file $crashmode $crashcmdfile
echo "#
# Crash Data Collection (Version $crashdc_version)
# $crashmode mode in use
#" > $crashoutput
if (( debug ));then
$crashexe -d $crashdebug $namelist $debuginfofile $vmcorefile < $crashcmd 2> ${crashcmd}.err
error=$?
else
$crashexe -s $namelist $debuginfofile $vmcorefile < $crashcmd >> $crashoutput 2> /dev/null
error=$?
fi
if (( error ));then
echo "Unable to generate $crashoutput"
exit 1
else
echo "File $crashoutput has been generated"
fi
#cleanup
if ! (( debug ));then
rm -f $crashcmd ${crashcmd}.err
fi
exit 0
|